I'm using web3 to transfer tokens between two wallets. I'm successfully generating and signing the transaction, a hash is being created, but is never updated to the network. I am using the Rinkeby test network. GETH is showing the transactions being created. I've waited several hours for the transactions, one of which I've waited over 24 hours so far.
Here's the raw transaction data before signing it and converting it to a hex string:
{
from: '0x1A9c7...',
to: '0xaed2df...',
nonce: '0x10',
gasPrice: '0x5208',
gasLimit: '0x670aac',
value: '0x00',
data: '0xa9059cbb0000000000...',
chainId: 4
}
Here's the code I'm using to generate the transaction, please note that web3legacy
is 0.20.x and web3
is 1.0.0-beta20
let sendTransaction = async () => {
const senderAddress = "0x1A9c7c...";
const destinationAddress = "0x2aABeb...";
const transferAmount = 100;
const nonce = web3legacy.eth.getTransactionCount(senderAddress);
const rawTransaction = {
from: senderAddress,
to: contractAddress,
nonce: web3legacy.toHex(nonce),
gasPrice: web3legacy.toHex(web3legacy.eth.estimateGas({from: senderAddress, to: destinationAddress, amount: web3legacy.toWei(0, "ether")})),
gasLimit: web3legacy.toHex((await web3.eth.getBlock("latest")).gasLimit),
value: "0x00",
data: contract.transfer.getData(destinationAddress, transferAmount, { from: senderAddress }),
chainId: 4
};
// senderAddress private_key
const privateKeySnapshot = await walletsRef.child(senderAddress).once('value');
const rawPrivateKey = privateKeySnapshot.val();
const privateKey = new Buffer(rawPrivateKey, "hex");
const transaction = new Transaction(rawTransaction);
transaction.sign(privateKey);
console.log("Validation:", transaction.validate());
const serializedTransaction = transaction.serialize();
web3legacy.eth.sendRawTransaction('0x' + serializedTransaction.toString("hex"), (err, hash) => {
if(err) console.error("ERROR:", err);
else {
console.log("HASH:", hash);
}
});
};
The validation from transaction.validate()
is successful.
The hash is created from the sendRawTransaction
method but it never appears on the rinkeby network, and my wallet/tokens are never affected. I get the common error message "Sorry, we are unable to locate that Transaction Hash" from rinkeby etherscan.
For anyone curious, sendSignedTransaction in 1.0.0 is currently bugged and doesn't work per issue #1102 which is why I brought in 0.20.0 to send a raw transaction