I am Writing a simple script for ERC20 token transfer method. which sign transaction offline and then submit it to network.
Transfer method encoded data :
var encoded = await MyContract.methods
.transfer(receiver_address, 10);
To get nonce of sender account :
var nonce = await web3.eth.getTransactionCount(
sender_address,
"pending"
);
To get estimateed Gas of latest block:
let estimatedGas = await web3.eth.estimateGas({
"from" : sender_address,
"nonce" : nonce,
"to" : address_contract,
"data" : encoded.encodeABI(),
});
Here i create a tx object using ethereumjs-tx cdn link:
let privateKey = new ethereumjs.Buffer.Buffer(key, 'hex')
var tx = {
nonce: nonce,
gasPrice: web3.utils.toHex(gasPrice),
gasLimit: web3.utils.toHex( estimatedGas + 1000000),
to: address_contract,
data: encoded.encodeABI(),
};
let tx_object = new ethereumjs.Tx(tx , { chain: 'ropsten' })
tx_object.sign(privateKey)
let serializedTx = tx_object.serialize();
Then i submit transaction to ropsten test net:
web3.eth.sendSignedTransaction('0X'+serializedTx.toString('hex'))
.on("transactionHash", function (hash) {
document.getElementById("error").innerHTML =
"Transaction Hash :" + hash;
});
Gas Limit of transaction is :
Gas Limit:1051110 also tried with gas Limit of latest block 8000029
Gas Price of transaction is :
Gas Price:0.000000002 Ether (2 Gwei)
But my problem here is that transactions get stuck at pending state from two days. i am attaching image and link to contract address
link of contract: https://ropsten.etherscan.io/address/0xdc11d98aa50b99a948a4fc2e159c30c5ba9a8364
following are version of web3 and etherumjs-tx:
- web3 version 1.0.0-beta.34 (also tried 1.0.0-beta.26 and @latest)
- Ethereumjs-tx version ethereumjs-tx-1.3.3
I don't think that there is problem with my gas Price or gas Limit.