Deploying Smart Contracts with Hardhat
This is a guide to creating and deploying smart contracts with Hardhat on the Syscoin NEVM.
NOTE: Syscoin is designed to be a settlement layer for zkRollups and other L2s/execution layers, as such it has a 2.5 minute block time for the optimal settlement security, it is advised to create dApps using zkRollups rather than using the Syscoin blockchain itself for executing smart contracts. You can find zkRollup resources here.
info
Syscoin's public NEVM test network is the Syscoin NEVM Testnet, sometimes labeled “Tanenbaum”. We'll use the Syscoin NEVM naming throughout this guide.
This guide assumes that you have already:
- Installed npm on your system
- Prepared a Syscoin NEVM wallet with a funded deployment account
1. Install Hardhat and create a project#
To install Hardhat use the following command:
Make a new directory where you wish to create your project then cd into it and run the command below:
Select Create a JavaScript project and follow the prompts.
Then enter this command to install the necessary dependencies:
2. Create a new contract#
Create a new file in the contracts directory called HelloNEVM.sol.
Paste the following code into the HelloNEVM.sol file.
note
The MIT license header keeps the example broadly reusable. Swap in the SPDX identifier that matches your project’s licensing before shipping real contracts.
3. Configure the network used by Hardhat#
Create a .env file in the project root and populate it with your endpoints and deployment key (keep the 0x prefix on the key).
Then update hardhat.config.js with the following, which includes the necessary configuration for contract verification:
Note: Check the file into .gitignore (Hardhat does this by default) so secrets stay out of source control.
4. Deploy the contract#
Open scripts/deploy.js (created by Hardhat) and replace its contents with the script below.
Run the usual Hardhat checks before deploying:
Once everything passes, deploy the contract (swap to mainnet to target the Syscoin mainnet).
You will then receive something similar to the following output showing that the contracts have been successfully deployed.
Congratulations! Your contracts have been deployed and you can see the contract's address in the output, which is worth saving if you wish to interact with it at a later date.
5. Verify the Contract#
After deploying your contract, it is a best practice to verify it on the block explorer. This makes your code publicly visible and auditable, and it allows others to interact with your contract directly from the explorer's UI.
Syscoin's explorers are compatible with Hardhat's verification tool. To verify the HelloNEVM contract, run the following command, replacing YOUR_CONTRACT_ADDRESS with the address you received after deployment.
For the Syscoin NEVM Testnet:
You can view your verified contract on the testnet explorer: https://explorer.tanenbaum.io
For Syscoin Mainnet:
You can view your verified contract on the mainnet explorer: https://explorer.syscoin.org
Because of the customChains configuration you added to hardhat.config.js, Hardhat knows how to communicate with the Syscoin explorers without any further setup.