From 3425f8252cb96c0011ebb3c72ba59883189608ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Mon, 21 Feb 2022 18:50:38 +0000 Subject: [PATCH] fix: Ethereum errors on send --- lib/plugins/wallet/geth/base.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index 31515a8d..332d4f71 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -41,6 +41,7 @@ function connect (url) { } const hex = bigNum => '0x' + bigNum.integerValue(BN.ROUND_DOWN).toString(16) +const bn2bn = bn => BN(bn.toString(16), 16) function privateKey (account) { return defaultWallet(account).getPrivateKey() @@ -115,9 +116,9 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) { return Promise.all(promises) .then(([gas, gasPrice, txCount]) => [ - gas, - gasPrice, - _.max([txCount, lastUsedNonces[fromAddress] + 1]) + bn2bn(gas), + bn2bn(gasPrice), + _.max([1, txCount, lastUsedNonces[fromAddress] + 1]) ]) .then(([gas, gasPrice, txCount]) => { lastUsedNonces[fromAddress] = txCount @@ -126,20 +127,20 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) { ? amount.minus(gasPrice.times(gas)) : amount - const contract = web3.eth.contract(ABI.ERC20).at(toAddress) - const rawTx = { chainId: 1, nonce: txCount, gasPrice: hex(gasPrice), - gasLimit: gas, + gasLimit: hex(gas), to: toAddress, from: fromAddress, value: isErc20Token ? hex(BN(0)) : hex(toSend) } - if (isErc20Token && contract) { - rawTx.data = contract.transfer.getData(toAddress, hex(toSend)) + if (isErc20Token) { + const contract = web3.eth.contract(ABI.ERC20).at(toAddress) + if (contract) + rawTx.data = contract.transfer.getData(toAddress, hex(toSend)) } const tx = new Tx(rawTx)