Connecting to the private node - cogeorg/teaching GitHub Wiki
With your private node running, open a new terminal and type
$ geth attach
to connect to this node. It will log something like
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.9-stable-ff9b1461/linux-amd64/go1.10
coinbase: 0x2dff1a0f45fcb8797da2122b5d3dca57f44411c3
at block: 21 (Wed, 30 May 2018 17:20:53 CEST)
datadir: /home/user/Ethereum/private
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>
and waits for your commands. Make sure that you are connected to the right node by checking the datadir and the coinbase address.
Managing Accounts
eth.accounts
will list all your acounts.eth.coinbase
will give you the first account that receives the mining reward.eth.getBalance(eth.accounts[1])
will give you the balance of the account #1 in Weiweb3.fromWei(eth.getBalance(eth.accounts[1]), "ether"))
will give you the balance of the account #1 in Etherpersonal.newAccount("passphrase")
will create a new account with the password being passphrase.personal.unlockAccount(eth.accounts[1], "passphrase", 300)
will unlock account #1 for 300 seconds.
Interacting with the mining
miner.stop()
stops the mining processminer.start(2)
starts the mining process with 2 threads
Transfering Ether
Finally, we will send 10 Ether from the coinbase account to account #1
> eth.sendTransaction({from: eth.coinbase, to: eth.accounts[1], value: web3.toWei(10, "ether")})
"0x0a7fcdadff83956c24b8e46981e014bd0a6bc751894daf3ecb71c4a39be902fe"
It returns the transaction hash. If you switch back to the terminal where your node is running, you will find the transaction there, too.
INFO [05-30|17:43:08] Submitted transaction fullhash=0x0a7fcdadff83956c24b8e46981e014bd0a6bc751894daf3ecb71c4a39be902fe recipient=0xD17d41ABC3a2e2276b5709883391E70c9bF1595d
Quitting the console
Just type
> exit
A comprehensive list of all commands can be found here.