0.1.1 • Published 3 years ago

etherscan-util v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

etherscan-util Build Status npm

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>;