Hardhat
This section will guide you through deploying a smart contract on the Viction using Hardhat.
Last updated
This section will guide you through deploying a smart contract on the Viction using Hardhat.
Last updated
Before you begin, ensure you've:
Download .
An ethereum wallet.
Funded your wallet for caring gas fee of transactions.
To create an empty Hardhat project, run the following commands:
Select Create a TypeScript project
then press enter to confirm the project root.
Select y
for both adding a .gitignore
and loading the sample project. It will take a moment for the project setup process to complete.
In order to deploy smart contracts to the Viction, you will need to configure your Hardhat project and add the Viction network.
To configure Hardhat to use Viction, add Viction as a network to your project's hardhat.config.ts
file:
The above configuration uses the @nomicfoundation/hardhat-toolbox
plugin to bundle all the commonly used packages and Hardhat plugins recommended to start developing with Hardhat.
To install @nomicfoundation/hardhat-toolbox
, run:
To install dotenv
, run:
Once you have dotenv
installed, you can create a .env
file with the following content:
Substitute <YOUR_PRIVATE_KEY>
with the private key for your wallet.
Below is a simple token contract (ERC20) written in the Solidity programming language:
To add the OpenZeppelin Contracts library to your project, run:
In your project, delete the contracts/Lock.sol
contract that was generated with the project and add the above code in a new file called contracts/MyToken.sol.
To compile the contract using Hardhat, run:
Once your contract has been successfully compiled, you can deploy the contract to the Viction networks.
To deploy the contract to the Viction testnet, you'll need to modify the scripts/deploy.ts
in your project:
Note
Gas limit is required when deploying a smart contract using Hardhat in Viction
Finally, ensure your wallet has enough fund to cover gas fee and run script with command:
VicScan now support contract verification via Hardhat API, you will need to change hardhat.config.ts with the following configuration:
It is recommended that the contract be deployed and verified using several files rather than a single file to let the verification process go more smoothly using the hardhat plugin.
Because verifying contracts requires compiling the source code to bytecode and comparing it to the bytecode on onchain, occasionally the source code might be a large file size, causing the compilation to take longer than usual.
It is strongly advised that those source code files be flattened into numerous files with less than 1MB each file to ensure performance and stability.
In the event the contract has previously been deployed in the single file format, but the verification procedure has failed. It is recommended that you re-deploy the contract with different file formats and continue the verification procedure.
The above configuration also uses to load the PRIVATE_KEY
environment variable from a .env
file to process.env.PRIVATE_KEY
. You should use a similar method to avoid hardcoding your private keys within your source code.
The Solidity code above defines a smart contract named ERC20
. The code uses the ERC20
interface provided by the to create a token smart contract. OpenZeppelin allows developers to leverage battle-tested smart contract implementations that adhere to official ERC standards.
The contract will be deployed on the Viction testnet. You can view the deployment status and contract by using and searching for the address returned by your deploy script. If you've deployed an exact copy of the token contract above, it will be verified, and you'll be able to read and write to the contract using the web interface.