Search code examples
ethereumgeth

Geth eth.sendTransaction does not work


I'm learning ethereum and tried private network with Geth 1.7.3-stable.

Accounts[0] has 105 eth in private network and I tried to send eth like below.

But eth.sendTransaction command returns only "0xaf571929f95ddeaab8761d719dba3c852f5d4f9895968a905c275561eaf57ae6".

And accounts[1] doesn't receive any eth.

> eth.getBalance(eth.accounts[0])
105000000000000000000
> personal.unlockAccount(eth.accounts[0])
Unlock account 0x24636f1423f131f5441fbee83323c53c59af247d
Passphrase: 
true
>  eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(2, 'ether')})
"0xaf571929f95ddeaab8761d719dba3c852f5d4f9895968a905c275561eaf57ae6"
> 
> eth.getBalance(eth.accounts[1])
0

Does anyone know how to fix this?


Solution

  • First, check and make sure the transaction is reaching your blockchain. Set up a listener using

    web3.eth.filter("pending").watch(
        function(error,result){
            if (!error) {
                console.log('Tx Hash: ' + result);
            }
        }
    )
    

    Once the listener is set up, run your sendTransaction again and confirm you're getting the log statement. If so, you're submitting the transaction correctly.

    As mentioned in the comment, next thing is to make sure the transaction is mined. There's a few ways you can do this:

    1. You can mine in the geth console. If you didn't start geth in console mode, you would need to either restart it, or attach to it via geth attach in another terminal. In the geth console, you can start mining with miner.start(). It will return null, but you should see activity in your geth output indicating mining has started. To stop mining, type miner.stop().
    2. You can download a separate mining app, like ethminer. Just download it and start it while geth is still running.

    Any pending transactions should be picked up.