Deploy a Contract with Hardhat
Overview
Hardhat is one of the popular smart contract development frameworks. It is the Merlin’s preferred framework, and therefore used in the Merlin as a default for deploying and automatically verifying smart contracts.
Prerequisites
Before you begin, you will need to prepare the following:
Prepare one EVM account。
Send some BTC to the account as gas fee 。 You can first bridge some BTC via Merlin Bridge (https://merlinchain.io/bridge) and send the BTC to your EVM account used to deploy contracts.
Initialize Hardhat project
mkdir <project-name>;cd <project-name>
Initialize a project with Hardhat:
npx hardhat
.Next, (… To avoid failure … please go slow with this cli dialogue…)
Press
<ENTER>
to set the project root.Press
<ENTER>
again to accept addition of.gitignore
.Type
n
to reject installingsample project's dependencies
.The idea here is to postpone installing dependencies to later steps due to a possible version-related bug.
Configure Hardhat project
Open the hardhat.config.js
file and paste the below code:
Add smart contract
Create a new file, in the contracts folder, named
Counter.sol
:touch contracts/Counter.sol
.Copy the below code and paste it in the Counter contract code:
Add deploy script
Create a new file in the scripts folder
deploy-counter.js
:touch scripts/deploy-counter.js
.Add the code below to the
deploy-counter.js
file:
Compile and deploy
Before compiling the contract, you need to install the toolbox. You may need to change directory to install outside the project. Use this command:
Compile your contract code (i.e., go back to the project root in the CLI):
Now run the scripts:
Here’s an output example:
Counter contract deployed to
https://testnet-scan.merlinchain.io/address/0x5bB1814A9226eFB912d439fdBcB59ce802aDCBB8
Last updated