Thursday, 19 January 2017

Installation and Commands of Geth client of Ethereum

1. Install Ethereum client in Ubuntu:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

2. Initialize the private blockchain:

Add below in genesis.json
{
    "nonce": "0x0000000000000042",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "difficulty": "0x4000",
    "alloc": {},
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "Custom Ethereum Genesis Block",
    "gasLimit": "0xffffffff"
}
geth init genesis.json
3. Run geth:

geth --networkid 42 --nodiscover --maxpeers 3 console

4. Add a new account:

personal.newAccount()

5. Start mining:

geth --mine --minerthreads=4 --networkid 42 --nodiscover --maxpeers 0 console
6. Unlock Account:

personal.unlockAccount(eth.coinbase)
7. Transfer money:

eth.sendTransaction({from: '0x4487xxxx40a4xxxx2de0xxxxdec1xxxx186fxxxx', to: '0x9a0dxxxx91cexxxx3034xxxx1800xxxx0b86xxxx', value: web3.toWei(1, "ether")})
8. Check account balance:


eth.getBalance(eth.accounts[0])
balance = eth.getBalance(eth.accounts[0]);

9. Set coinbase

> miner.setEtherbase(eth.accounts[1]);
> eth.coinbase;


10. Start/Stop Mining:

> miner.start(8)
> miner.stop()


11. Start/Stop RPC

admin.startRPC("privateIp", 8545, "*", "web3,net,eth")

> admin.stopRPC()

Or
geth --rpc --rpcaddr <ip> --rpcport <portnumber>  --rpcapi "web3,net,personal,eth"

12. RPC call:

curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' http://public-ip:3000
{"jsonrpc":"2.0","id":67,"result":"42"}

13. Add a peer:

admin.nodeInfo
admin.addPeer(nodeURL)
The nodeURL needs to be in enode URL format.

14. Get the Contract code of a given Account address

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xa94f", "0x2"],"id":1}'

Parameters:
The address, and an integer block number.

15.  Create Contract or Send Transaction

(1). Create a new Contract
params: [{
  "from": "0xb60e8dd61c5d32be8058bb8",
  "data": "0xd46e8dd67c5d32be8d46e8d"
}]
from: the address the transaction is sent from.
data: The compiled code of a contract.

(2) Send a Transaction:

params: [{
  "from": "0xb60e8dd61c5d32be8058bb8",
  "to": "0xd46e8dd67c5d32be8058bb8eb",
  "gas": "0x76c0", // 30400,
  "gasPrice": "0x9184e72a000", // 10000000000000
  "value": "0x9184e72a", // 2441406250
  "data": "0xd46e8dd67c5d32be8d46e8d"
}]

to: The address the transaction is directed to.
value: Integer of the value send with this transaction.
data: the hash of the invoked method signature and encoded parameters.
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{see above}],"id":1}'

16. Eth Call

Executes a new message call immediately without creating a transaction on the block chain.


curl -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{see above}],"id":1}'

Returns the return value of executed contract.

17. Get Transaction Receipt

Return the entire Transaction object info by Transaction hash code.
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xb903239f8"],"id":1}'



Reference:
https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console
http://hypernephelist.com/2016/05/30/deploying-a-private-Ethereum-blockchain.html
https://github.com/ethereum/go-ethereum/wiki/Managing-Your-Accounts
http://ethdocs.org/en/latest/network/index.html


1 comment:

  1. Invest in Ethereum on eToro the World's Leading Social Trading Network...

    Join 1,000,000's who have already discovered easier strategies for investing in Ethereum...

    Learn from experienced eToro traders or copy their positions automatically!

    ReplyDelete