2

I am trying to sign and send a transaction as follows:

let signedTx  = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
let txReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
...

The PRIVATE_KEY variable is a 40-character long hexadecimal string, without an 0x prefix.

The options variable is an object containing to, data and gas fields.

My code completes successfully on Ganache, but when I run it on a fully-synced Parity node connected to ropsten, I get the following error:

Insufficient funds.
The account you tried to send transaction from does not have enough funds.
Required 8000000000000000 and got: 0.

My account definitely has more than 0 ether on ropsten (see https://ropsten.etherscan.io/address/0x1c492da58f6396be2880576cc513c5b108450429), and I can even verify it locally (via web3.js):

let balance = await this.web3.eth.getBalance("0x1c492da58f6396be2880576cc513c5b108450429");
console.log(balance);

So here is the thing.

I was able to resolve this problem by adding 0x at the beginning of the PRIVATE_KEY variable.

Hence my question - is it possible that web3.eth.accounts.signTransaction runs differently on Ganache and on Parity?

Thank you!

1 Answer 1

1

OK, I've finally figured this out.

When I open Ganache, it automatically unlocks each one of the accounts specified by the --account flag (or 10 default accounts if no accounts are specified). So the private keys of those accounts are not even needed here in order to sign and send transactions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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