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 hex = bigNum => '0x' + bigNum.integerValue(BN.ROUND_DOWN).toString(16)
|
||||||
|
const bn2bn = bn => BN(bn.toString(16), 16)
|
||||||
|
|
||||||
function privateKey (account) {
|
function privateKey (account) {
|
||||||
return defaultWallet(account).getPrivateKey()
|
return defaultWallet(account).getPrivateKey()
|
||||||
|
|
@ -115,9 +116,9 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(([gas, gasPrice, txCount]) => [
|
.then(([gas, gasPrice, txCount]) => [
|
||||||
gas,
|
bn2bn(gas),
|
||||||
gasPrice,
|
bn2bn(gasPrice),
|
||||||
_.max([txCount, lastUsedNonces[fromAddress] + 1])
|
_.max([1, txCount, lastUsedNonces[fromAddress] + 1])
|
||||||
])
|
])
|
||||||
.then(([gas, gasPrice, txCount]) => {
|
.then(([gas, gasPrice, txCount]) => {
|
||||||
lastUsedNonces[fromAddress] = txCount
|
lastUsedNonces[fromAddress] = txCount
|
||||||
|
|
@ -126,20 +127,20 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
||||||
? amount.minus(gasPrice.times(gas))
|
? amount.minus(gasPrice.times(gas))
|
||||||
: amount
|
: amount
|
||||||
|
|
||||||
const contract = web3.eth.contract(ABI.ERC20).at(toAddress)
|
|
||||||
|
|
||||||
const rawTx = {
|
const rawTx = {
|
||||||
chainId: 1,
|
chainId: 1,
|
||||||
nonce: txCount,
|
nonce: txCount,
|
||||||
gasPrice: hex(gasPrice),
|
gasPrice: hex(gasPrice),
|
||||||
gasLimit: gas,
|
gasLimit: hex(gas),
|
||||||
to: toAddress,
|
to: toAddress,
|
||||||
from: fromAddress,
|
from: fromAddress,
|
||||||
value: isErc20Token ? hex(BN(0)) : hex(toSend)
|
value: isErc20Token ? hex(BN(0)) : hex(toSend)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isErc20Token && contract) {
|
if (isErc20Token) {
|
||||||
rawTx.data = contract.transfer.getData(toAddress, hex(toSend))
|
const contract = web3.eth.contract(ABI.ERC20).at(toAddress)
|
||||||
|
if (contract)
|
||||||
|
rawTx.data = contract.transfer.getData(toAddress, hex(toSend))
|
||||||
}
|
}
|
||||||
|
|
||||||
const tx = new Tx(rawTx)
|
const tx = new Tx(rawTx)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue