Merge pull request #1137 from chaotixkilla/fix-erc20-transfers
Fix ERC-20 transfer gas estimation and receiver address
This commit is contained in:
commit
e3a1bb8f47
1 changed files with 9 additions and 3 deletions
|
|
@ -102,12 +102,20 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
|||
const isErc20Token = coins.utils.isErc20Token(cryptoCode)
|
||||
const toAddress = isErc20Token ? coins.utils.getErc20Token(cryptoCode).contractAddress : _toAddress.toLowerCase()
|
||||
|
||||
let contract, contractData
|
||||
if (isErc20Token) {
|
||||
contract = web3.eth.contract(ABI.ERC20).at(toAddress)
|
||||
contractData = isErc20Token && contract.transfer.getData(_toAddress.toLowerCase(), hex(toSend))
|
||||
}
|
||||
|
||||
const txTemplate = {
|
||||
from: fromAddress,
|
||||
to: toAddress,
|
||||
value: amount.toString()
|
||||
}
|
||||
|
||||
if (isErc20Token) txTemplate.data = contractData
|
||||
|
||||
const promises = [
|
||||
pify(web3.eth.estimateGas)(txTemplate),
|
||||
pify(web3.eth.getGasPrice)(),
|
||||
|
|
@ -138,9 +146,7 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
|||
}
|
||||
|
||||
if (isErc20Token) {
|
||||
const contract = web3.eth.contract(ABI.ERC20).at(toAddress)
|
||||
if (contract)
|
||||
rawTx.data = contract.transfer.getData(toAddress, hex(toSend))
|
||||
rawTx.data = contractData
|
||||
}
|
||||
|
||||
const tx = new Tx(rawTx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue