@xdapps/erc-token-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

ERC Token Utils

This is a basic wrapper around Ethers.js with static methods for interacting with ERC-20, ERC-721, or ERC-1155 contracts.

Basics

  1. Import the protocol you want to interact with.
  2. Pass in a contract address with a provider and then you can call any of the static methods.

How To Use

import {ERC20} from "@xdapps/erc-token-utils"
const contractAddress = "0x.....";
const provider = new ethers.JsonRpcProvider("RPC_URL_ADDRESS");
const name = await ERC20.getName(contractAddress, provider);
const symbol = await ERC20.getSymbol(contractAddress, provider);
const decimals = await ERC20.getDecimals(contractAddress, provider);
const supply = await ERC20.getTotalSupply(contractAddress, provider);
const balance = await ERC20.balanceOf(contractAddress, provider);
//This method would require a provider with signer.
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);; //
const walletWithProvider = wallet.connect(this.provider);
const txResult = await ERC20.transferFrom(contractAddress, provider);

Readme

Keywords

none

Package Sidebar

Install

npm i @xdapps/erc-token-utils

Weekly Downloads

4

Version

1.0.9

License

ISC

Unpacked Size

47.1 kB

Total Files

34

Last publish

Collaborators

  • xdapps