etherscan-util
v0.1.1
Published
A package fetching contract ABI from etherscan
Downloads
7
Maintainers
Readme
etherscan-util
This package allows creating ethers.js contract instances without manually downloading ABI: etherscanUtil.getVerifiedContractAt('<address>')
. It supports Mainnet, BSC, and most testnets.
Installation
npm install etherscan-util
Usage
import ethers from "ethers";
import EtherscanUtil from "etherscan-util";
// You can also use `const EtherscanUtil = require('etherscan-util')`
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const etherscanUtil = new EtherscanUtil(provider, ETHERSCAN_API_KEY);
const contract = await etherscanUtil.getVerifiedContractAt('<address>');
It requires only contract address and will fetch the ABI for the contract automatically from Etherscan. If signer is not supplied to getVerifiedContractAt, it will initialize contract instance with provider/signer that was supplied to EtherscanUtil constructor.
Here are function definitions:
function constructor(
providerOrSigner: ethers.providers.Provider | ethers.Signer,
etherscanApiKey?: string);
async function getVerifiedContractAt(
address: string,
signer?: ethers.Signer
): Promise<ethers.Contract>;