Deprecation notice
Please use my slightly different erc20lookup lookup module that supports multitude of tokens via one single contract call with support of both ethers.js v5 and v6.
Quick loader of ERC20 token metadata
Simple on-chain lookup of name
, symbol
and decimals
. Supports both backend and frontend as well as web3 and ethers.js.
Usage with web3
import { ERC20 } from 'erc20-metadata';
const token = new web3.eth.Contract(ERC20.ABI, USDT_ADDRESS);
await ERC20(token);
console.log(token.erc20.symbol, token.erc20.name, token.erc20.decimals);
console.log(typeof token.erc20.decimals);
Usage with ethers.js
Exactly the same as web3:
const token = new ethers.Contract(USDT_ADDRESS, ERC20.ABI, provider);
await ERC20(token);
console.log(token.erc20.symbol, token.erc20.name, token.erc20.decimals);
Typescript support
See index.js
. This module is way too simple to be written in TypeScript. Contributions are welcome for the types support, though.
Tests
See index.js
. This module has no logic of it's own to test.