From b931f45df9200e1cc40fddd4c284f4a0f3c9a64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 19 May 2022 00:22:02 +0100 Subject: [PATCH] fix: USDT web3 calls --- lib/plugins/wallet/geth/base.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index 8720808d..13dfac01 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -79,14 +79,16 @@ function balance (account, cryptoCode, settings, operatorId) { const pendingBalance = (address, cryptoCode) => { const promises = [_balance(true, address, cryptoCode), _balance(false, address, cryptoCode)] - return Promise.all(promises).then(([pending, confirmed]) => pending.minus(confirmed)) + return Promise.all(promises).then(([pending, confirmed]) => BN(pending).minus(confirmed)) } const confirmedBalance = (address, cryptoCode) => _balance(false, address, cryptoCode) function _balance (includePending, address, cryptoCode) { if (coins.utils.isErc20Token(cryptoCode)) { - const contract = web3.eth.contract(ABI.ERC20).at(coins.utils.getErc20Token(cryptoCode).contractAddress) - return contract.balanceOf(address.toLowerCase()) + const contract = new web3.eth.Contract(ABI.ERC20, coins.utils.getErc20Token(cryptoCode).contractAddress) + return contract.methods.balanceOf(address.toLowerCase()).call((_, balance) => { + return contract.methods.decimals().call((_, decimals) => BN(balance).div(10 ** decimals)) + }) } const block = includePending ? 'pending' : undefined return pify(web3.eth.getBalance)(address.toLowerCase(), block) @@ -102,8 +104,8 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) { let contract, contractData if (isErc20Token) { - contract = web3.eth.contract(ABI.ERC20).at(toAddress) - contractData = isErc20Token && contract.transfer.getData(_toAddress.toLowerCase(), hex(toSend)) + contract = new web3.eth.Contract(ABI.ERC20, toAddress) + contractData = isErc20Token && contract.methods.transfer(_toAddress.toLowerCase(), hex(toSend)).encodeABI() } const txTemplate = {