The ERC20 contract in this Github repository utilises the OpenZeppelin contract library version 4.9.0. The contract is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, ERC20PausableUpgradeable, AccessControlUpgradeable, ERC20PermitUpgradeable, UUPSUpgradeable.
The contract specifies 4 contract roles: defaultAdmin, pauser, minter and upgrader.
Note
- defaultAdmin has the highest level of permissions. It can grant and revoke other roles, and perform any action within the contract.
- pauser can pause and unpause the contract.
- minter can mint new tokens.
- upgrader can upgrade the contract implementation
We recommend using Solidity compiler version 0.8.18
as defined in the hardhat.config.js
file.
- Open the repository on your preferred IDE.
- Run
npm install --save-dev hardhat
to install Hardhat. We will be using Hardhat to deploy the contract. - Run
npm install
to install dependencies. - Create a
.env
file at the project root and input your deployer wallet’s private key with the following format:PRIVATE_KEY="enter your private key here"
- In the
deploy.js
file under the scripts folder, input the following details:
- defaultAdmin address
- Token name
- Token symbol
- In this example, we have given the other 3 contract roles (pauser, minter and upgrader with a 0x0 address), since the defaultAdmin can perform all functions. Feel free to change this structure.
- Run
npx hardhat compile
to compile the contract files. - Run
npx hardhat run scripts/deploy.js --network fxMainnet
to deploy the contract on FunctionX mainnet. To deploy on FunctionX testnet, change the network tofxTestnet
in the command. Please ensure that your deployer wallet has sufficient FX to deploy the contract. - The terminal should print the contract address. Copy the contract address to view your deployed contract on Function X blockchain explorer. Here are the explorer links https://starscan.io/ (Mainnet) https://testnet.starscan.io/ (Testnet)
- You should notice that the contract address from step 8 above is a proxy address. The proxy address should point to an implementation address. For more information on proxy and implementation contracts, please refer here.
- Ensure that the implementation contract is verified. If the implementation contract is not verified, you may follow the steps below:
- In your code repository, go to
artifacts
folder. You should be able to see abuild-info
folder. Open the.json
file, and format it to make it more readable.
- Collapse the input range, and copy the "input" value. Paste and save it into another
.json
file. We will be using this.json
file for verification later.
- Go to the implementation contract, scroll down and select the "Code" tab. Select "Verify & Publish".
- Select "Verify via Standard Input JSON"
- Give your implementation contract a name (this will be the contract name), and select the compiler
v0.8.18+commit.87f61d96
. Upload the input JSON created, then select "Verify & publish".
- Your contract should be verified now.
- Go back to the proxy contract page. On the "Read Proxy" page, you should see that the
totalSupply
of your token is 1, or 1000000000000000000 wei.
- You will be able to mint more tokens as necessary. Go to the "Write Proxy" page, scroll down and you will see the mint function. Enter the address that you want to mint to. We suggest inputting the contract deployer address. The amount you want to mint should be in wei (10^8). Select ‘Write’, and ensure that the transaction is executed from a wallet that has the admin or minter role.
- Congratulations, you have successfully deployed an ERC20 token contract on FunctionX!