1

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

  • Is the web3 provider a geth or parity client? If so, their logs might contain debug information about why it's rejected, e.g. out of gas, etc. – Linmao Song Feb 9 '18 at 13:01
1

Your gas price is far too low. It should be at least 20 gwei (20000000000). The problem is that you're using estimateGas, which tells you how much gas you need, to come up with a gas price, which is how much ether you will pay per gas unit.

Similarly, your gasLimit is very high, but that's not a huge deal, since (assuming your call succeeds) you'll be refunded the excess. You could use estimateGas there, but be sure to estimate for your actual call, not a zero ether transfer.

  • How do I estimate the gas for the contract transfer instead of a 0-ether transaction? I'll try using 20 gwei. How do we calculate the gas price with the only function to help you decide the price of gas only gives you the minimum price. I've just been setting the gasPrice and gasLimit as I've seen in tutorials and documentation. – Christian Tucker Dec 22 '17 at 10:01
  • I just sent off another transaction using 2000 gwei as the gasPrice, so that's 100x more than what you recommended. let's see what happens. HASH: 0xfa5ab0003561bf2d11cec17439a8bd69a59afa3ea38bfb5fb19195be7218d770 – Christian Tucker Dec 22 '17 at 10:06
  • I should add that this doesn't show up as a pending transaction either. – Christian Tucker Dec 22 '17 at 10:18
  • I got the gas price from stats.rinkeby.io. A high gas limit shouldn't be a problem. rinkeby.etherscan.io is saying that the transaction hash you have is an "invalid search string." Are you sure that's right? – user19510 Dec 22 '17 at 13:59
  • Note that if you sent a new transaction with a higher nonce, it will be stuck behind the previous transaction. Can you share the address you're sending these transactions from and the nonces you've been using? – user19510 Dec 22 '17 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.