Deploying A Test Contract
Introduction
In this getting started tutorial, you will deploy a sample contract within Carbon's EVM module.
What You'll Need
Solidity Language Knowledge: For this guide, you write the smart contract code in Solidity programming language. Solidity is the primary programming language employed in Ethereum - designed specifically for writing smart contracts. This code will define the rules and logic of the smart contract, specifying how it will function and interact with the Carbon network.
A Carbon account: You will need a Carbon account to deploy the smart contract. The account will hold the necessary funds to pay for the gas fees required for the deployment.
Sufficient funds: Deploying a smart contract on the Ethereum network requires paying transaction fees, also known as gas fees. The fees are payable in Ether (ETH), the native cryptocurrency of the Ethereum network. You must have sufficient funds in your Ethereum account to cover the transaction fees.
A deployment script or plugin: You will need deployment tools like HardHat or Truffle, to deploy the smart contract on Carbon EVM. These tools will enable you to interact with the Carbon network and execute the smart contract deployment transaction.
Access to a Carbon node, either by running your own, connecting to a public node, or via an API key using a node service.
Guide
To deploy a Solidity Smart Contract via HardHat, you can follow these steps:
Step 1: Set up the development environment. Make sure to install the following prerequisites before setting up the project:
Step 2: Create a new project via npm init --y
.
Step 3: Install hardhat dependencies required for the deployment via npm install --save-dev hardhat
and npm install @nomicfoundation/hardhat-toolbox
.
Step 4: Create a new hardhat project by running npx hardhat
in your project directory. Ensure that the Create an empty hardhat.config.js
option is selected.
Step 5: Create or insert your smart contract in the contracts
directory. In this example, we will be using a sample ERC20 contract, named ERC20Token.sol
.
Sample contract:
Step 6: Create a deploy.js
script to deploy your contract under the scripts
directory.
Step 7: Configure HardHat to use the Carbon EVM via hardhat.config.js
.
Ensure that your private key is inserted into accounts
before running the next step.
Step 8: Deploy your contract by running npx hardhat run --network testnet scripts/deploy.js
.
In this example, we are deploying to the testnet
environment. The name of the environment should be the same as the one defined under networks
in hardhat.config.js
.
Step 9: If everything is working correctly, you should observe the corresponding logs being displayed on the console without any further errors.
Sample logs:
Congratulations, you’ve successfully deployed your first smart contract on Carbon EVM!
Last updated