Hardhat plugin fetching contract ABI from etherscan
npm install hardhat-etherscan-abiHardhat plugin that fetches verified contract ABI from Etherscan.
This plugin adds extra features on top of @nomiclabs/hardhat-ethers and allows creating contract instances without
manually downloading ABI: ethers.getVerifiedContractAt(''). It supports Mainnet, BSC, and most testnets.
``bash`
npm install --save-dev hardhat-etherscan-abi
And add the following statement to your hardhat.config.js:
`js`
require("hardhat-etherscan-abi");
Or, if you are using TypeScript, add this to your hardhat.config.ts:
`js`
import "hardhat-etherscan-abi";
This plugin creates no additional tasks.
This object has adds some extra hardhat-etherscan-abi specific functionalities by adding new extra fields to hre.ethers
These helpers are added to the ethers object:
`typescript`
export async function getVerifiedContractAt(
hre: HardhatRuntimeEnvironment,
address: string,
signer?: ethers.Signer
): Promise
You need to add the following Etherscan config to your hardhat.config.js file. Etherscan API key is optional but without it Etherscan allows only 1 request per 5 seconds.
`js`
module.exports = {
networks: {
mainnet: { ... }
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: "YOUR_ETHERSCAN_API_KEY"
}
};
Then use the function:
`js``
const contract = await hre.ethers.getVerifiedContractAt('');
It requires only contract address and will fetch the ABI for the contract automatically from Etherscan