ERC20 helper functions for nodejs / web, using enode proxy on etherscan.io
npm install https://github.com/funderstoken/erc20-token-lib-js
// or
yarn add https://github.com/funderstoken/erc20-token-lib-js
Please register an account on etherscan.io, and then create api-keys to use this library.
import { ERC20Token } from 'erc20-token-lib'
const aERC20Token = new ERC20Token({
network: 'mainnet', // or 'kovan' | 'rinkeby' | 'ropsten'
apikey: '<ETHERSCAN_APIKEY>', // string
tokenAddress: '<TOKEN_CONTRACT_ADDRESS>', // address string with prefix 0x
myAddress: '<END_USER_ACCOUNT_ADDRESS>', // optional, string with prefix 0x, if provided then also fetch user's token balance
});
aERC20Token.afterAllLoaded.then(aERC20Token => {
console.log(aERC20Token);
});
{
network: 'mainnet',
apikey: 'AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDD',
tokenAddress: '0x51c028bc9503874d74965638a4632a266d31f61f',
tokenName: 'Funder Smart Token',
symbol: 'FST',
decimals: 18,
myAddress: '0x71ea4d72535f9c92ea8fa99e32311bdbbaf34618',
balance: '1000000000000000800',
balanceHumanNumberString: '1.0000000000000008',
balanceDecimaledNumberString: '1000000000000000800',
totalSupply: '330000000000000000000000000',
totalSupplyHumanNumberString: '330000000',
totalSupplyDecimaledNumberString: '330000000000000000000000000',
infoLoaded: true,
balanceLoaded: true,
afterAllLoaded:
Promise {
[Circular],
domain:
Domain {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
members: [] } },
transfer: [Function],
updateMyTokenBalance: [Function],
intervalID: null,
intervalMS: 15000,
autoUpdateMyTokenBalanceEnabled: false,
enableAutoUpdateMyTokenBalance: [Function],
disableAutoUpdateMyTokenBalance: [Function] }
}
(Please refer to eth-key-lib-js
to fetch private keys)
aERC20Token.transfer(
'<EndUserPrivateKeyBuffer>',
'<ReceiverAddrses>',
'<transferringValueDecimaledNumberString>'
).then(txhash => console.log(txhash));
aERC20Token.enableAutoUpdateMyTokenBalance()
aERC20Token.disableAutoUpdateMyTokenBalance()