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.
Simple on-chain lookup of name, symbol and decimals. Supports both backend and frontend as well as web3 and ethers.js.
import { ERC20 } from 'erc20-metadata';
// import web3, connect to provider,
// Note: ERC20 ABI is included in this module for your convenience
const token = new web3.eth.Contract(ERC20.ABI, USDT_ADDRESS);
// Query the basic three metadata properties
await ERC20(token);
// `token.erc20` object has been added to `token`:
console.log(token.erc20.symbol, token.erc20.name, token.erc20.decimals);
// And `decimals` is a `Number`:
console.log(typeof token.erc20.decimals);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);See index.js. This module is way too simple to be written in TypeScript. Contributions are welcome for the types support, though.
See index.js. This module has no logic of it's own to test.