Skip to main content

Smart contracts

GitHub repository

Requirements

  1. Solidity compiler (hardhat)
  2. npm

Prepare environment

  1. Create a .env file starting from .env.example file and update the values accordingly.
PRIVATE_KEY_ISSUER='<priv_key>'
  1. In the hardhat.config.js specify the various networks to play around with different accounts.
  'hardhat-issuer': {
url: 'http://127.0.0.1:8545/',
chainId: 31337,
gas: 2100000,
gasPrice: 8000000000,
accounts: [process.env.PRIVATE_KEY_ISSUER],
},

Local Deployment

Smart contracts can be deployed on the hardhat local network. It is an EVM-like emulated chain.

  1. Clone the repository and install the dependecies.
npm install --save-dev
  1. Compile the contracts
npx hardhat compile
  1. Start a local node
npx hardhat node
  1. To fund issuer and other addresses
npx hardhat --network localhost faucet <eth-address>
  1. In other shell we can run the deploy script by specifying the local hardhat network
npx hardhat run --network hardhat-issuer scripts/deploy.js

Run the scripts

  1. Deploy the contracts
npx hardhat run --network shimmerevm-testnet scripts/deploy.js
  1. Run the various scripts to play with the contracts
npx hardhat run --network <your-network> scripts/<script.js>

Verify the deployed smart contracts code

Verifying a contract means making its source code public, along with the compiler settings you used, which allows anyone to compile it and compare the generated bytecode with the one that is deployed on-chain.

  1. Modify the hardhat config by adding the etherscan information as follows:
    module.exports = {
solidity: "0.8.18",
settings: {
...
},
networks: {
...
},
etherscan: {
apiKey: {
'shimmerevm-testnet': 'ABCDE12345ABCDE12345ABCDE123456789'
},
customChains: [
{
network: 'shimmerevm-testnet',
chainId: 1071,
urls: {
apiURL: 'https://explorer.evm.testnet.shimmer.network/api',
browserURL: 'https://explorer.evm.testnet.shimmer.network/'
}
}
]
}
};
  1. Verify the SCs' code:
npx hardhat verify --network shimmerevm-testnet <contract address> "<contract constructor Arg1>" "<contract constructor Arg2>"