Deploy and verify an ERC-20 token
Step 1
First we’re going to create a new folder and install hardhat:
$ mkdir mock-token$ cd mock-token
$ npm init
$ npm install --save-dev hardhatNow let’s bootstrap a hardhat project. Select the option "Create an empty hardhat.config.js":
$ npx hardhat Let’s also create a couple of folders for our files:
$ mkdir scripts contractsNow install some dependencies to our project:
$ npm install --save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
$ npm install --save-dev @nomiclabs/hardhat-etherscan
Step 2
Let’s now create a first Solidity contract at contracts/Token.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MockToken is ERC20 {
constructor() ERC20("Mock Token", "Mock") {
_mint(msg.sender, 1000000 * 10**decimals());
}
}We need to install openzeppelin library to our file:
Try to compile the contract with:
Step 3
We should prepare our hardhat.config.js file as:
Step 4
Now let’s add the deploy script. To keep it simple we’ll simply reuse the deploy script from the Hardhat tutorial, so let’s create the file scripts/deploy.js:
After wrote our script, we can call deploy file:
Last updated
Was this helpful?