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!

0

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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