fix: Ethereum errors on send
This commit is contained in:
parent
0ff73687eb
commit
3425f8252c
1 changed files with 9 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue