poma / etherscan-util

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

License:MIT License


Languages

Language:TypeScript 95.0%Language:JavaScript 5.0%