fix: ERC-20 transfer gas estimation and receiver address

This commit is contained in:
Sérgio Salgado 2022-02-28 16:18:05 +00:00
parent 4339e58e6a
commit b816b195c9

View file

@ -101,6 +101,7 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
const isErc20Token = coins.utils.isErc20Token(cryptoCode) const isErc20Token = coins.utils.isErc20Token(cryptoCode)
const toAddress = isErc20Token ? coins.utils.getErc20Token(cryptoCode).contractAddress : _toAddress.toLowerCase() const toAddress = isErc20Token ? coins.utils.getErc20Token(cryptoCode).contractAddress : _toAddress.toLowerCase()
const contractData = isErc20Token && contract.transfer.getData(_toAddress.toLowerCase(), hex(toSend))
const txTemplate = { const txTemplate = {
from: fromAddress, from: fromAddress,
@ -108,6 +109,8 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
value: amount.toString() value: amount.toString()
} }
if (isErc20Token) txTemplate.data = contractData
const promises = [ const promises = [
pify(web3.eth.estimateGas)(txTemplate), pify(web3.eth.estimateGas)(txTemplate),
pify(web3.eth.getGasPrice)(), pify(web3.eth.getGasPrice)(),
@ -140,7 +143,7 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
if (isErc20Token) { if (isErc20Token) {
const contract = web3.eth.contract(ABI.ERC20).at(toAddress) const contract = web3.eth.contract(ABI.ERC20).at(toAddress)
if (contract) if (contract)
rawTx.data = contract.transfer.getData(toAddress, hex(toSend)) rawTx.data = contractData
} }
const tx = new Tx(rawTx) const tx = new Tx(rawTx)