Token Balances
This commit is contained in:
1 parent
6784e6bd0b
commit
5ac6f32bb7
3 files changed
+86
-71
No files matched your search
+47
-1
@@ -115,7 +115,53 @@ exports.newWeb3Server = function newWeb3Server() {
|
||||
|
||||
for (let j = 0; j < walletAccount.tokenBalances.length; j++) {
|
||||
let tokenBalance = walletAccount.tokenBalances[j]
|
||||
tokenBalance.value = 0
|
||||
|
||||
if (tokenBalance.referenceParent === undefined) { continue }
|
||||
if (tokenBalance.referenceParent.parentNode === undefined) { continue }
|
||||
if (tokenBalance.referenceParent.smartContracts === undefined) { continue }
|
||||
|
||||
if (tokenBalance.referenceParent.config.codeName === undefined) {
|
||||
tokenBalance.error = 'Reference Parent without config.codeName defined.'
|
||||
continue
|
||||
}
|
||||
|
||||
if (tokenBalance.referenceParent.smartContracts.config.address === undefined) {
|
||||
tokenBalance.error = 'Reference Parent Smart Contract without config.address defined.'
|
||||
continue
|
||||
}
|
||||
|
||||
let tokenContractAddress = tokenBalance.referenceParent.smartContracts.config.address
|
||||
// The minimum ABI to get ERC20 Token balance
|
||||
let minABI = [
|
||||
// balanceOf
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "_owner", "type": "address" }],
|
||||
"name": "balanceOf",
|
||||
"outputs": [{ "name": "balance", "type": "uint256" }],
|
||||
"type": "function"
|
||||
},
|
||||
// decimals
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [{ "name": "", "type": "uint8" }],
|
||||
"type": "function"
|
||||
}
|
||||
];
|
||||
|
||||
let contract = new web3.eth.Contract(minABI, tokenContractAddress);
|
||||
|
||||
try {
|
||||
tokenBalance.value = await contract.methods.balanceOf(walletAccount.config.address).call()
|
||||
} catch (err) {
|
||||
if (err.message.indexOf('Provided address') >= 0) {
|
||||
walletAccount.error = 'Invalid configured address.'
|
||||
} else {
|
||||
walletAccount.error = err.message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user