Contract Deployment Examples
Deployment examples for OVM 2.0
Please refer to the Github Examples Repo. There are currently three examples and we are adding more every few days:
hardhat-simple-storage - shows how to deploy a storage contract to Habtor testnet.
init-fund-l2 - shows how to deposit funds from L1 to L2, on Habtor testnet
truffle-erc20 Simple ERC20 Token Truffle Tutorial
We'll work though one of those examples in more detail.
Simple ERC20 Token Truffle Tutorial
Hi there! Welcome to our ERC20 Truffle example. If you're interested in writing your first L2 smart contract using Truffle as your smart contract testing framework, then you've come to the right place. This repo serves as an example for how go through and compile/test/deploy your contracts on BSC mainnet and the Habtor L2.
Let's begin.
Step 1: Compile your contracts
Compiling a contract for Habtor is identical to compiling a contract for BSC mainnet. Notably, all standard solidity compiler versions can be used. For this ERC20, we will use 0.6.12. Create a truffle-config.js and add the following to it:
const HDWalletProvider = require('@truffle/hdwallet-provider')
require('dotenv').config()
const env = process.env
const pk_1 = env.pk_1
const pk_2 = env.pk_2
module.exports = {
contracts_build_directory: './build',
networks: {
habtor_testnet: {
provider: function () {
return new HDWalletProvider({
privateKeys: [pk_1, pk_2],
providerOrUrl: 'https://testnet.habtor.com',
})
},
network_id: 28,
host: 'https://testnet.habtor.com',
}
},
compilers: {
solc: {
version: '0.6.12',
},
},
}Now add a .env file that follows the format of env.example with two private keys. NOTE: these accounts must be funded, i.e. contain enough testnet BNB to cover the cost of the deployment. Then,
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!
Step 2: Testing your contract
Woot! It's time to test our contract. Since the JSON RPC provider URL (for Habtor testnet) has already been specified in your Truffle config file, all we need to do next is run the test command. Run:
You should see a set of passing tests for your ERC20 contract.
If so, congrats! You're ready to deploy an application to Habtor. It really is that easy.
Step 3: Deploying your Contract
Now we're going to deploy a contract using truffle. For Truffle based deployments, we're going to use Truffle's migrate command to run a migrations file for us that will deploy the contract we specify.
First, let's create that migrations file. Create a new directory called migrations in the topmost path of your project and create a file within it called 1_deploy_ERC20_contract.js.
Next, within 1_deploy_ERC20_contract.js, we're going to add the following logic:
Now we're ready to run our migrations 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:
That's pretty much it. Contracts deployed! Tutorial complete. Hopefully now you know the basics of working with Habtor network! π ΎοΈ
Troubleshooting
Example project not working? [Create a Github Issue]https://github.com/habtorcom/optimism-v2/issues).
Last updated