ierc20-token.js 913 B

1234567891011121314151617181920212223242526272829303132
  1. const SimpleWeb3 = require('./simple-web3')
  2. const Config = require('../../config/config')
  3. class IERC20 {}
  4. IERC20.batchInit = async function (context, ierc20TokenAddressList) {
  5. IERC20.contractMap = {}
  6. // 初始化token
  7. for (const tokenHash of ierc20TokenAddressList) {
  8. await IERC20.initTokenByHash(context, tokenHash)
  9. }
  10. }
  11. IERC20.initTokenByHash = async function (context, tokenHash) {
  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