Fixed eth balance script to display correct tokens
This commit is contained in:
parent
aadd3418f9
commit
0ea0fbe8c8
|
@ -2,6 +2,7 @@
|
|||
"name": "ethereum-balance",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"web3": "1.0.0-beta.55"
|
||||
"web3": "1.0.0-beta.55",
|
||||
"bignumber.js": "9.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const Web3 = require('web3')
|
||||
const BN = require('bignumber.js')
|
||||
|
||||
const { HOME_RPC_URL, HOME_TOKEN_ADDRESS } = process.env
|
||||
|
||||
|
@ -12,5 +13,6 @@ const address = process.argv[2]
|
|||
web3.eth.getBalance(address).then(x => console.log(`${x.toString()} wei`))
|
||||
|
||||
token.methods.balanceOf(address).call()
|
||||
.then(x => parseFloat(new BN(x).dividedBy(10 ** 18).toFixed(8, 3)))
|
||||
.then(x => console.log(`${x.toString()} tokens`))
|
||||
.catch(() => console.log('0 tokens'))
|
||||
|
|
Loading…
Reference in New Issue