Hardhat is an Ethereum development tool designed to facilitate the deployment, testing, and debugging of smart contracts. It provides a streamlined experience for developers working with Solidity contracts.
For those new to Hardhat, we recommend exploring the official documentation to get acquainted. The following instructions utilize npm to initialize a project and install dependencies:
First, incorporate the Testnet network into your hardhat.config.ts:
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
const config: HardhatUserConfig = {
solidity: '0.8.24',
networks: {
testnet: {
url: 'https://testnet.evm.nodes.onflow.org',
accounts: [`<PRIVATE_KEY>`], // In practice, this should come from an environment variable and not be commited
gas: 500000, // Example gas limit
},
},
};
export default config;
To keep this example straightforward, we've included the account's private key directly in hardhat.config.ts. However, it is crucial to avoid committing private keys to your Git repository for security reasons. Instead, opt for using environment variables for safer handling of sensitive information.
To verify your contract on Flowscan, you can update your Hardhat config file as such including the correct chainID, apiURL and browserURL:
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import "@nomicfoundation/hardhat-verify";
const PRIVATE_KEY = vars.get("EVM_PRIVATE_KEY");
const config: HardhatUserConfig = {
solidity: '0.8.24',
networks: {
testnet: {
url: 'https://testnet.evm.nodes.onflow.org',
accounts: [PRIVATE_KEY], // In practice, this should come from an environment variable and not be commited
gas: 500000, // Example gas limit
},
},
etherscan: {
apiKey: {
// Is not required by blockscout. Can be any non-empty string
'testnet': "abc"
},
customChains: [
{
network: "testnet",
chainId: 545,
urls: {
apiURL: "https://evm-testnet.flowscan.io/api",
browserURL: "https://evm-testnet.flowscan.io/",
}
}
]
},
sourcify: {
enabled: false
}
};
export default config;
The verify plugin requires you to include constructor arguments with the verify task and ensures that they correspond to expected ABI signature. However, Blockscout ignores those arguments, so you may specify any values that correspond to the ABI. Execute the following command to verify the contract: