I got an error when using web3js to call the smart contract method transferFrom:
“Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!”
net: https://ropsten.infura.io/v3/21a58c52b*********************080
my code:
async transferFrom(fromAddress, toAddress, amount) {
let nonce = await this.w3.eth.getTransactionCount(fromAddress)
let gasPrice = await this.w3.eth.getGasPrice()
let contract = await this.useConstract()
let rawTx = {
from: fromAddress,
to: this.contractInfo.contractAddress,
value: this.w3.utils.toHex(this.w3.utils.toWei('0', 'ether')),
nonce: this.w3.utils.toHex(nonce++),
gasLimit: this.w3.utils.toHex(150000),
gasPrice: this.w3.utils.toHex(gasPrice.toString()),
// gasPrice: this.w3.utils.toHex(this.w3.utils.toWei('10', 'gwei')),
data: contract.methods.transferFrom(fromAddress, toAddress, this.w3.utils.toHex(amount.toString())).encodeABI()
}
var signRaw = await this.w3.eth.accounts.signTransaction(rawTx, this.privateKey);
// let tx = new EthereumTx(rawTx, { chain: ethereumjsNet , hardfork: 'petersburg' })
// tx.sign(Buffer.from(this.privateKey, 'hex'))
// let serializedTx = tx.serialize();
// let raw = '0x' + serializedTx.toString('hex')
var test = this.w3.eth.sendSignedTransaction(signRaw['rawTransaction']).then(result => {
console.log(result)
return result
}).catch(error => {
console.log(error.message)
})
return test
}
It is normal when I call the contract method “transfer”
my code :
async transferToken(fromAddress, toAddress, amount) {
let nonce = await this.w3.eth.getTransactionCount(fromAddress)
let gasPrice = await this.w3.eth.getGasPrice()
let contract = await this.useConstract()
let rawTx = {
from: fromAddress,
to: this.contractInfo.contractAddress,
value: this.w3.utils.toHex(this.w3.utils.toWei('0', 'ether')),
nonce: this.w3.utils.toHex(nonce++),
gasLimit: this.w3.utils.toHex(50000),
gasPrice: this.w3.utils.toHex(gasPrice.toString()),
data: contract.methods.transfer(toAddress, this.w3.utils.toHex(amount.toString())).encodeABI()
}
// action: use EthereumTx 2.0.0, need set chain
let tx = new EthereumTx(rawTx, { chain: ethereumjsNet , hardfork: 'petersburg' })
tx.sign(Buffer.from(this.privateKey, 'hex'))
let serializedTx = tx.serialize();
let raw = '0x' + serializedTx.toString('hex')
return await this.w3.eth.sendSignedTransaction(raw)
}