Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error from invalid private key for signTransaction #1998

Closed
little-shippy opened this issue Oct 15, 2018 · 2 comments
Closed

Incorrect error from invalid private key for signTransaction #1998

little-shippy opened this issue Oct 15, 2018 · 2 comments
Labels
Bug Addressing a bug
Projects

Comments

@little-shippy
Copy link

Hey guys,

I was running into an issue where I was getting an insufficient funds error when trying to sign a transaction. I found that this is a fairly common issue on the forums and it can be caused by having a private key that doesn't start with a 0x.

There is a simple solution to this in the packages/web3-eth-accounts/src/index.js file on line 145:

if (!privateKey) {
    error = new Error('No private key given!');

    callback(error);
    return Promise.reject(error);
}

if (!privateKey.startsWith('0x')) {
    error = new Error('Private key is invalid!');

    callback(error);
    return Promise.reject(error);
}

https://github.com/ethereum/web3.js/blob/v1.0.0-beta.36/packages/web3-eth-accounts/src/index.js#L145

I tested this from the v1.0.0-beta.36 tag and all tests passed.

@therightstuff
Copy link

@little-shippy i've been struggling this for weeks and couldn't find a solution anywhere - thank you!!!

@therightstuff
Copy link

sadly, i've finally had a chance to try this and i'm still getting a nonsensical insufficient funds error (the exact same unsigned transaction works just fine with sendTransaction).

using the develop branch and ethereumjs-tx-1.3.3.min.js:

var Buffer = ethereumjs.Buffer.Buffer;
var ethereumjsTx = ethereumjs.Tx;

...

// create transaction
var transaction = {
    "from": sourceAccount, // required
    "to": targetAccount, // required
    "value": web3.toHex(valueWei), // required
    "gas": web3.toHex(gasLimit),
    "gasLimit": web3.toHex(gasLimit),
    "gasPrice": web3.toHex(gasPrice),
    "chainId": web3.version.network,
    "nonce": web3.toHex(nonce)
};

var tx = new ethereumjsTx(transaction);
var privateKey = Buffer.from(testAccountPrivateKey, 'hex');
tx.sign(privateKey);
var rawTransaction = '0x' + tx.serialize().toString('hex');
transactionHash = web3.eth.sendRawTransaction(rawTransaction);

@nivida nivida added the Bug Addressing a bug label Nov 28, 2018
@nivida nivida added this to To do in 1.0 Nov 28, 2018
@nivida nivida closed this as completed Feb 27, 2019
1.0 automation moved this from To do to Done Feb 27, 2019
@nivida nivida mentioned this issue Oct 21, 2019
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
No open projects
1.0
  
Done
Development

No branches or pull requests

3 participants