We'll work through that one in this quick tutorial. The example linked above is a simple smart contract that allows you to store a single value and retrieve it.
It's a great starting point for learning how to deploy a contract to Boba. Let's begin.
Compiling a contract for Boba is identical to compiling a contract for Ethereum mainchain. Notably, all standard solidity compiler versions can be used. For this contract, we will use 0.8.9.
If you check the hardhat.config.ts file, you'll see the following configuration in essence:
Now add a .env file that follows the format of env.example with your private key. NOTE: this account must be funded, i.e. contain enough Sepolia ETH to cover the cost of the deployment. Then,
hardhat compile
Yep, it's that easy. You can verify that everything went well by looking for the build directory that contains your new JSON files. Now let's move on to testing!
Woot! It's time to test our contract. Since the JSON RPC provider URL (for Boba Sepolia) has already been specified in your Hardhat config file, all we need to do next is run the test command. Run:
yarn test:integration
You should see a set of passing tests for your contract. You can check a production-grade project here: LightBridge.
$hardhattesttest/contract.spec.ts--show-stack-tracesUsingnetwork'boba_sepolia'.Compilingyourcontracts...===========================> Everything is up to date, there is nothing to compile.yourtestsContractdeployedat:0x5FbDB2315678afecb367f032d93F642f64180aa3√alwayssucceedsContractdeployedat:0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512√contractdeployed2passing (3s)✨Donein3s.
If so, congrats! You're ready to deploy an application to Boba. It really is that easy.
Now we're going to deploy a contract using hardhat.
First, let's create that deployment file. Create a new directory called deploy in the topmost path of your project and create a file within it called contract.deploy.ts.
Next, within contract.deploy.ts, we're going to add the following logic:
console.log(`'Deploying contract...`)constprovider=hre.ethers.providerconstnetwork=hre.networkconsole.log(`Network name=${network?.name}`)constdeployer=newWallet(network.config.accounts[0], provider)constFactory__YourContract=newethers.ContractFactory(YourContractJson.abi,YourContractJson.bytecode, deployer)let gasLimit =prompt("Custom gas limit? [number/N]")if (isNaN(gasLimit?.toLowerCase())) { gasLimit =null;} else { gasLimit =parseInt(gasLimit)}YourContract =awaitFactory__YourContract.deploy({gasLimit})let res =awaitYourContract.deployTransaction.wait()console.log(`Deployed contract: `, res)console.log(`Contract deployed to: ${YourContract.address}`)
Now we're ready to run our deployment file! Let's go ahead and deploy this contract:
After a few seconds your contract should be deployed. Now you'll see this in your terminal:
$yarndeployyarnrunv1.22.15$hardhatdeploy--networkboba_sepoliaCompilingyourcontracts...===========================> Everything is up to date, there is nothing to compile.Startingdeploymentscripts...======================> Network name: 'boba_sepolia'contract.deploy.ts==========================Deploying'YourContract'----------------->transactionhash:0xe7cc5d048ffd426587b7d9c89aed4b0d7b2bd29c5532300bce8a9a57a4c4d689>Blocks:0Seconds:0>contractaddress:0xE769105D8bDC4Fb070dD3057c7e48BB98771dE15>blocknumber:6270>blocktimestamp:1635787822>account:0x21724227d169eAcBf216dE61EE7dc28F80CF8A92>balance:0.901997296123301024>gasused:855211 (0xd0cab)>gasprice:0.02gwei>valuesent:0ETH>totalcost:0.00001710422ETH>Savingartifacts------------------------------------->Totalcost:0.00001710422ETHSummary=======> Total deployments: 1> Final cost: 0.00001710422 ETH✨Donein10.11s.
That's pretty much it. Contracts deployed! Tutorial complete. Hopefully now you know the basics of working with Boba!