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

Insufficient funds error with sendTransaction using account signing #2489

Closed
guifel opened this issue Mar 12, 2019 · 6 comments
Closed

Insufficient funds error with sendTransaction using account signing #2489

guifel opened this issue Mar 12, 2019 · 6 comments

Comments

@guifel
Copy link

guifel commented Mar 12, 2019

Description

Using beta 48. I try to send a transaction from an address with sufficient balance with the private key stored in the account module.

Expected behavior

Transaction should go through (Or display a different error message if I am missing something).

Actual behavior

Balance:  39558999999999700
(node:5972) UnhandledPromiseRejectionWarning: Error: Node error: {"code":-32000,"message":"insufficient funds for gas * price + value"}
    at Function.validate (/home/felley/Documents/Liquidity/test/node_modules/web3-providers/dist/web3-providers.cjs.js:365:18)
    at /home/felley/Documents/Liquidity/test/node_modules/web3-providers/dist/web3-providers.cjs.js:708:57
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Steps to reproduce the behavior

const web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/<API_KEY>'));
const alicePrivateKey ='<PRIV_KEY>'
web3.eth.accounts.wallet.add(alicePrivateKey)
const alice = web3.eth.accounts.privateKeyToAccount(alicePrivateKey).address
web3.eth.getBalance(alice).then(x => console.log("Balance: ", x.toString()))
const bob = '0x829bd824b016326a401d083b33d092293333a830'
web3.eth.sendTransaction({from: alice, to: bob, value: "100", gas: 30000, gasPrice:'1000000000'}).then(x => console.log(x))

The same code works for beta 36. On beta 46 I get the error TypeError: Cannot create property 'from' on string '0xf86303843b9aca0082753094829bd824b016326a401d083b33d092293333a83064802ca039e64f244297c5791cc004dfdb82036f270594d0e60254f8095d24a987a481e5a072f761082059a356c9be2997bf90a6ef6afab3e61b7758385aec80d4e9af21f9' at Object.inputTransactionFormatter

Tried on nodejs and Chrome.

Versions

  • web3.js: beta 48
  • nodejs: v8.10.0
  • ethereum node: infura and local parity node
@nivida nivida added the support label Mar 12, 2019
@nivida
Copy link
Contributor

nivida commented Mar 12, 2019

The returned value from getBalance is in wei this means the balance of this account is ~0.03955 ether. Which isn't enough for executing this transaction.

@guifel
Copy link
Author

guifel commented Mar 12, 2019

The balance is enough:
(1000000000*30000+100)*10**-18 = 0.00003 < 0.03955

As I said, the same works on beta 36

@OFRBG
Copy link

OFRBG commented Mar 12, 2019

Since I don't have access to the specifics of your env, could you test the same code but with gas price set to 0? That could help us narrow it down, @guifel.

@guifel
Copy link
Author

guifel commented Mar 12, 2019

With gasPrice set to 0
Selection_317

If I don't specify any gas price I get the same error as on my issue description.

@nivida
Copy link
Contributor

nivida commented Mar 12, 2019

There is already an existing issue about this and I think we should discuss it here.

@guifel Yep, this is correct I was wrong because I thought the value property is in ether. In the issue, I've referenced above are some additional information about this.

@nivida nivida closed this as completed Mar 12, 2019
@leberknecht
Copy link

For the logs: One reason why this could happen is missing hex-encoding of the gas values:

let rawTx = {
  nonce: web3.toHex(nonce),
  to: null,
  data: bytedata,
  gasPrice: web3.toWei('2', 'gwei'),
  gas: (318019 * 2),
  value: '0x00'
}

you would think this means we will pay 318019 * 2 = 636038 gas, by a price of 2gwei, should be = 1272076 gwei = 0.001272076 ether.
But with 0.20.x i get this error on Kovan-testnet:

The account you tried to send transaction from does not have enough funds. Required 150745611034260441820719413536 and got: 992632048000000000

which is ~150745611034 ether ^^
fix:

let rawTx = {
[...]
  gasPrice: web3.toHex(web3.toWei('2', 'gwei')),
  gas: web3.toHex((318019 * 2)),
}

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

4 participants