ierc20-token.js 900 B

123456789101112131415161718192021222324252627282930313233
  1. const SimpleWeb3 = require('./simple-web3')
  2. class IERC20 {}
  3. IERC20.batchInit = async function (context, ierc20TokenAddressList) {
  4. IERC20.contractMap = {}
  5. // 初始化token
  6. for (const tokenHash of ierc20TokenAddressList) {
  7. await IERC20.initTokenByHash(context, tokenHash)
  8. }
  9. }
  10. IERC20.initTokenByHash = async function (context, tokenHash) {
  11. const config = context.config
  12. // 合约初始化
  13. IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(config.BASE_ABI, tokenHash)
  14. }
  15. IERC20.getTokenName = async function (tokenHash) {
  16. return await IERC20.contractMap[tokenHash].methods.name().call()
  17. }
  18. IERC20.getTokenSymbol = async function (tokenHash) {
  19. return await IERC20.contractMap[tokenHash].methods.symbol().call()
  20. }
  21. IERC20.getDecimals = async function (tokenHash) {
  22. return await IERC20.contractMap[tokenHash].methods.decimals().call()
  23. }
  24. module.exports = IERC20