@xdapps/erc-token-utils
v1.0.9
Published
Basic functions to interact with standard ERC protocols using Ethers.js
Downloads
3
Readme
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
- Import the protocol you want to interact with.
- 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);