eth.sendTransaction() example

jonk88jonk88 Member Posts: 8
edited June 2017 in web3-js
I am trying to to a transfer from my personal wallet into my coinbase wallet so I can convert to USD. I have been looking at many examples of how do a transfer with geth between two accounts, but no matter what I try I get one of two errors.

If I do not include gas/gasPrice I get...

Error: exceeds block gas limit

I looked up the current gasLimit eth.getBlock("latest").gasLimit and got 5000.
So I went to http://ethgasstation.info/calculator.php and saw 40 gwei is the fastest execution. So in Geth I try this...

web3.eth.sendTransaction({from: 'myWallet', to: 'coinbaseWallet', value: web3.toWei(0.1,'ether'),gas: 5000, gasPrice: web3.toWei(40,'gwei')});

And I get the error: insufficient funds for gas * price + value

I have .2 in my account right now, and no matter how low I set the ether value, I still get the insufficient funds error.

Anyone know what I'm doing wrong?

Thanks

Comments

  • strikingtanstrikingtan Member Posts: 7
    What version are you using of geth?
  • jonk88jonk88 Member Posts: 8

    What version are you using of geth?

    1.6.5-stable-cf87713d
    Thanks. I updated my code to convert everything to Hex. My call now looks like this.

    //web3.toWei(0.1, 'ether'); var ethVal = 100000000000000000; var gasVal = 5000; //web3.toWei(40, 'gwei') var gasPrice = 40000000000; var ethHex = '0x' + ethVal.toString(16); var gasHex = '0x' + gasVal.toString(16); var gpHex = '0x' + gasPrice.toString(16); web3.eth.sendTransaction({from: 'myWallet', to: 'coinbaseWallet', value: '0x016345785d8a0000', gas: '0x1388', gasPrice: '0x09502f9000'});

    I still get the insufficient funds error
  • strikingtanstrikingtan Member Posts: 7
    edited June 2017
    "This error is common if you don't have enough eth in your account, if your node isn't in sync with the network, or if you don't specify a gas price or something else is slightly wrong with the command."

    Do any of these apply to you?
  • jonk88jonk88 Member Posts: 8

    "This error is common if you don't have enough eth in your account, if your node isn't in sync with the network, or if you don't specify a gas price or something else is slightly wrong with the command."

    Do any of these apply to you?

    Im still syncing... 1000 blocks to go
  • strikingtanstrikingtan Member Posts: 7
    jonk88 said:

    "This error is common if you don't have enough eth in your account, if your node isn't in sync with the network, or if you don't specify a gas price or something else is slightly wrong with the command."

    Do any of these apply to you?

    Im still syncing... 1000 blocks to go
    Let me know how it works out once you're in sync.
  • jonk88jonk88 Member Posts: 8
    finally got it! yea, I just needed to be more patient and let it fully sync. thanks
  • strikingtanstrikingtan Member Posts: 7
    jonk88 said:

    finally got it! yea, I just needed to be more patient and let it fully sync. thanks

    No problem! If you feel that this helped, donate at 0xC37582e0A2CC7223dE7eB303F40A2D2A5193e478. Even 0.01 ether helps :)
  • nana123nana123 Member Posts: 4
    This information is very interesting and thanks for the good information.





  • strikingtanstrikingtan Member Posts: 7
    nana123 said:

    This information is very interesting and thanks for the good information.





    No problemo. Send any donations to 0xC37582e0A2CC7223dE7eB303F40A2D2A5193e478 - it helps fund my Ethereum research
  • BikuyBikuy Member Posts: 36
    Looks like you aren't fully synced.

  • WhiteOutMashupsWhiteOutMashups Kuala Lumpur, MalaysiaMember Posts: 5
    Yes this happened to me when my node wasn't fully synced. The exact same error
  • EtherGeekEtherGeek Member Posts: 34
    edited December 2017
    I have written a small scrypt to simplyfy everything. My command is (at the linux command prompt of a full working/synched node) sendeth &ltamount in eth&gt &lteth addr&gt [gas price in Gwei]. an example to send 0.1 eth to 0x362c89a6d8a1597ff41eb03e1E897d0d95827C54 and a gaz price of 1.355 Gwei would be

    ethsend 0.1 0x362c89a6d8a1597ff41eb03e1E897d0d95827C54 1.355

    #!/bin/bash

    . ~/.geth.conf
    MAX=6000

    # default gaz 53 Gwei
    GAZP=53

    # default account is first account, set GETH_ACC to specifiy another one
    if [ "$GETH_ACC" = "" ]; then
    GETH_ACC=0
    fi
    if [ $# -lt 2 ] || [ $# -gt 3 ]; then
    echo Error, ussage: sendeth ether adr [gazprice]
    exit
    fi
    if [ $# -eq 3 ]; then
    GAZP=$3
    fi
    echo $(date "+%Y-%m-%d %H:%M:%S") trying $1 $2 $GAZP >> ~/sendeth.log
    tmpfile=/tmp/sendeth.js
    [ -f $tmpfile ] && rm $tmpfile
    echo personal.unlockAccount\(eth.accounts[$GETH_ACC]\) > $tmpfile
    echo eth.sendTransaction\(\{from: eth.accounts[$GETH_ACC], to: \"$2\", value: web3.toWei\($1, \"ether\"\), gasPrice: web3.toWei\($GAZP, \"Gwei\"\)\}\) >> $tmpfile
    # echo eth.sendTransaction\(\{from: eth.accounts[$GETH_ACC], to: \"$2\", value: web3.toWei\($1, \"ether\"\)\}\) >> $tmpfile
    bb=$(balance)
    geth --exec 'loadScript("/tmp/sendeth.js")' attach ipc:/$DIR/geth.ipc
    echo Please wait for transaction to confirm... \(max $MAX seconds\)
    I=0
    while [ $I -lt $MAX ]; do
    gone=$(echo $bb - $(balance) | bc -l)
    if [ $gone != 0 ]; then
    sleep 15
    gone=$(echo $bb - $(balance) | bc -l)
    if [ $gone != 0 ]; then
    echo Transaction completed with success, balance reduced by $gone, new balance $(balance)
    echo $(date "+%Y-%m-%d %H:%M:%S") sendeth $1 $2 from $GETH_ACC fee $(echo $gone - $1 | bc -l) in $I seconds | tee -a ~/sendeth.log
    exit
    fi
    fi
    sleep 1
    let I=I+1
    done
    echo Problem, please check to make sure your transaction did not work
    echo for the moment your balance does not appear to be reduced [$bb]
    echo but this could change if all transactions are not received
    echo please check before resending
    .geth.conf is a small config file that contains the location of the .ethereun directory and looks like this

    DIR=/crypto/ethereum/geth/.ethereum
Sign In or Register to comment.