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

An error "insufficient funds for gas * price + value" is thrown #1

Open
metanomad21 opened this issue Mar 5, 2023 · 2 comments
Open

Comments

@metanomad21
Copy link

When executing sendSignedTransaction, an error "insufficient funds for gas * price + value" is thrown. Can you please advise on the reason? Both userAddr and pub_addr have been confirmed to have sufficient balance.

@jmanOBO
Copy link

jmanOBO commented Mar 26, 2023

When executing sendSignedTransaction, an error "insufficient funds for gas * price + value" is thrown. Can you please advise on the reason? Both userAddr and pub_addr have been confirmed to have sufficient balance.

Yes by default the code attempts to transfer 1ETH (10e18 wei) . U should check the balance of the address to know how much to spend and also provide room for the gass price .

@unnamed-lab
Copy link

I encountered this and here was my fix:

const gasPrice: bigint = await web3.eth.getGasPrice();
const gasLimit: bigint = 22000n;
const txFee: bigint = BigInt(Math.floor(Number(gasPrice) * 1.666));
const funds: bigint = BigInt(amount - txFee * gasLimit);

From the error stated

"insufficient funds for gas * price + value"

The funds to send is the value - gas * gassPrice

const funds: bigint = BigInt(amount - txFee * gasLimit);

This solves the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants