0

I am sending 1 eth from one account to another account. But I am unable to understand why the required balance is too big. I am receiving following error message:

Error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 1096934302059488651232480448211091758313913168 and got: 9999999999999999999999999999999999.

I am using following script to send transaction:

const Web3 = require("web3"); //version "^0.20"
const Tx = require('ethereumjs-tx') //version "^1.3.4"
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));


function sendBalance(address, amountInEth){
    var addressFrom= "0x00B2386D9...............7DE370BF5B1d4893";
    var privateKey = new Buffer('d549079....................2ae7de5', 'hex')

    const gasPriceHex = web3.toHex(10);

    var nonceval = web3.eth.getTransactionCount(addressFrom);

    var fTx = {
        nonce: nonceval,
        gasPrice: gasPriceHex,
        gasLimit: web3.toHex(210000),
        from: addressFrom,
        to: address,
        value: web3.toWei(amountInEth, 'ether')
    };

    var txx = new Tx(fTx);
    txx.sign(privateKey);

    var sTx =txx.serialize();
    console.log("Current Balance:",web3.eth.getBalance(addressFrom).toString());
    console.log("Transaction:",fTx)
    web3.eth.sendRawTransaction('0x' + sTx.toString('hex'), (err, hash) => {
        if (err) { console.log(err); return; }

        // Log the tx, you can explore status manually with eth.getTransaction()
        console.log('Tx Hash: ' + hash);
    });
}


// usage
sendBalance("0x004ec........................9513386F32E",1)

The output and error I receive with this script is as follows:

Current Balance: 9.999999999999999999999999999999999e+33
Transaction: { nonce: 0,
  gasPrice: '0xa',
  gasLimit: '0x33450',
  from: '0x00B2386........................B1d4893',
  to: '0x004ec07..........................386F32E',
  value: '1000000000000000000' }
Error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 1096934302059488651232480448211091758313913168 and got: 9999999999999999999999999999999999.

Note: Address and private keys have been modified to include minimal and relevant content.

1 Answer 1

1

The problem was that the value was expected to be a hex value, but I was sending integer. Correction in script is in var fTx:

value: web3.toHex(web3.toWei(amountInEth, 'ether'))

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.