Deploy Smart Contract

You can also add an array of accounts (defined by their private key) for the corresponding network to be used by the provider. Note that the account will have to have enough native token funds, this will be tGGG if you're interacting with the Genesis L2 Devnet. This balance is to cover the contract deployment costs on the network.

Write a deployment script

You can create a deployment script in a new file in the scripts directory, for example, deploy.ts. This script should include the necessary code to deploy the smart contract to the Genesis L2 Devnet using the deploy function provided by Hardhat.

sync function main() {
  // Load the contract and get the contract factory
  const MyContract = await ethers.getContractFactory('MyContract');

  // Deploy the contract to the Genesis L2 network
  const contract = await MyContract.deploy();

  // Wait for the contract to be deployed
  await contract.deployed();

  console.log('Contract deployed to:', contract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Deploy the smart contract

Run your deployment script using the following command, using the --network tag to the Genesis L2 Devnet test network you have defined in the config:

# deploy to Genesis L2 Devnet 
npx hardhat run --network GenesisL2Devnet scripts/deploy.ts

Verify

You can then run the hardhat verify task, passing the address of the contract, the network where it's deployed, and the constructor arguments that were used to deploy it (if any):

npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"

If your contract has multiple constructor arguments like the preset ERC721, you will need to save your constructor arguments to a separate file like arguments.js in the root directory as so:

module.exports = [
  'string argument', // string arguments
  50, // numerical arguments
  { x: 10, y: 5 }, // struct arguments
  '0xabcdef', // bytes arguments
  '0x123567', // address arguments
];

The verification command then becomes:

npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS --constructor-args arguments.js

See the guide in the Hardhat docs for more information and other ways to verify your contract.

Last updated