-
Install ethereum client (geth).
-
Mac
brew tap ethereum/ethereum brew install ethereum
-
Linux (Debian)
sudo apt-get install software-properties-common sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install ethereum
-
Windows install from here
-
-
Install Mist Browser from here
-
Note: edit all values wrapped in <> (no <> after edit)
-
Initialize Private BlockChain
geth --identity "testethChain" --rpc --rpcaddr "0.0.0.0" --rpcport "3333" --rpccorsdomain "*" --datadir "</full/path/to/store/blockchain>" --port "33333" --nodiscover --rpcapi "admin,miner,personal,db,eth,net,web3" --networkid <anyIntMoreThan2> init </full/path/to/genesis.json> geth --identity "testethChain" --rpc --rpcaddr "0.0.0.0" --rpcport "3333" --rpccorsdomain "*" --datadir "/home/amitj/testeth/ethereum" --port "33333" --nodiscover --rpcapi "admin,miner,personal,db,eth,net,web3" --networkid 333 init /home/amitj/testeth/ethereum/genesis.json genesis.json Example: { "nonce": "0x0000000000000033", "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x00", "gasLimit": "0x33000000", "difficulty": "0x3000", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { }, "config": { "chainId": 33, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 } }
-
Start Ethereum client as private net
geth --fast --cache 512 --ipcpath "</full/path/to/store/blockchain/testchain.ipc>" --identity "testethChain" --rpc --rpcaddr "0.0.0.0" --rpcport "3333" --rpccorsdomain "*" --datadir "<dir/path/as/in/initialize>" --port "33333" --nodiscover --rpcapi "admin,miner,personal,db,eth,net,web3" --networkid <idAsInInitialize> console geth --fast --cache 512 --ipcpath "/home/amitj/testeth/ethereum/testchain.ipc" --identity "testethChain" --rpc --rpcaddr "0.0.0.0" --rpcport "3333" --rpccorsdomain "*" --datadir "/home/amitj/testeth/ethereum" --port "33333" --nodiscover --rpcapi "admin,miner,personal,db,eth,net,web3" --networkid 333 console
-
Connect to Ethereum client in next terminal, used as work geth console
geth attach ipc:</full/path/to/store/blockchain/testchain.ipc> geth attach ipc:/home/amitj/testeth/ethereum/testchain.ipc
-
Create new user & unlock it
personal.newAccount("password") personal.unlockAccount(personal.listAccounts[0], "password")
-
Start a miner
miner.setEtherbase(listAccounts[0]) // Set miner miner.start() // Start miner session miner.stop() // Stop miner session
-
Start Mist browser using (another) terminal, correct gethpath as per your system
mist --rpc --rpcaddr "0.0.0.0" --rpcport "3333" </full/path/to/store/blockchain/testchain.ipc> --gethpath /usr/local/bin/geth
-
Follow step 1 of above.
-
Copy same
genesis.json
(step 4 above) used previously to another nodes' machine.{ "nonce": "0x0000000000000033", "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x00", "gasLimit": "0x33000000", "difficulty": "0x3000", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { }, "config": { "chainId": 33, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 } }
-
Initialize blockchain in next machine with same networkid.
geth --datadir="</any/path/dir>" init genesis.json geth --datadir="/home/amitj/testeth/ethereum/node2/chain" init genesis.json
-
Now, open geth console with same networkid.
geth --ipcpath="</any/path/dir/testchain.ipc>" --rpc --rpccorsdomain "*" --datadir="</any/path/dir>" --networkid 333 --nodiscover console geth --ipcpath="/home/amitj/testeth/ethereum/node2/testchain.ipc" --rpc --rpccorsdomain "*" --datadir="/home/amitj/testeth/ethereum/node2/chain" --networkid 333 --nodiscover console
-
Using geth console, Connect to hosted private ethereum node. If you already dont have node info, use
admin.nodeInfo.enode
in geth console of host node to findadmin.addPeer(<connection node info>) admin.addPeer("enode://85a14cfdff34ac51e51186229235d131edd4a5f62284eac9a3a998e1b0bf087a82a44d83010949ac899ffd355683522b88a87db78fcd235293b9e6e1b06ec139@192.168.0.102:33333?discport=0")
-
Check if successfully connected.
admin.peers
-
Attach new geth console to this chain for executing geth commands
geth attach ipc:</any/path/dir/testchain.ipc> geth attach ipc:/home/amitj/testeth/ethereum/node2/testchain.ipc
-
Create transaction
tx = {from: <hash_of_sender_account>, to: <hash_of_receiver_account>, value: web3.toWei(<amount_to_send>, <coin_unit>)} tx = {from: "0x2a1476cd7681e4b45b89b0792019d481bca469c0", to: "0x59429d6106e98dc914622315e408b7aa4998d8f3", value: web3.toWei(1.23, "ether")}
-
Push transaction to network
personal.sendTransaction(tx, <sender_passphrase>) personal.sendTransaction(tx, "1")
-
Check account's balance
web3.fromWei(eth.getBalance(primary), <coin_unit>) web3.fromWei(eth.getBalance(primary), "ether")
- Download and install Mist Browser from here
- Mantain atleast one account with atleast 1 Ether (start miner to generate ether)
- Select CONTRACTS tap in top right
- Click DEPLOY NEW CONTRACT
- Select account to deploy contract with (must have atleast 1 ETH)
- Paste solidity code in TextCode box, a Select option will appear (right side of textbox)
- Select Contract to deploy and fill init values if any.
- Click Deploy and enter account passphrase
- If any miner is running in the network, you can view deployed Contract in CONTRACTS tab.
- Follow this tutorial
-
JSON Interface can be found in Mist Browser CONTRACT_INFO page after deployed.
-
Geth code to connect to SmartContract
var myContract = eth.contract(<JSON_Interface>).at(<Contract_Address>); var smartMultiReward = eth.contract([ { "constant": true, "inputs": [ { "name": "user", "type": "address" } ], "name": "showRewardTypes", "outputs": [ { "name": "", "type": "bytes32[]", "value": [] } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "spender", "type": "address" }, { "name": "value", "type": "uint256" }, { "name": "rewardType", "type": "bytes32" }, { "name": "spentOnMsg", "type": "string" } ], "name": "spendReward", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "user", "type": "address" }, { "name": "rewardType", "type": "bytes32" } ], "name": "showMyReward", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "value", "type": "uint256" }, { "name": "rewardType", "type": "bytes32" } ], "name": "setAvailRewardPoints", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "owner", "outputs": [ { "name": "", "type": "address", "value": "0x2a1476cd7681e4b45b89b0792019d481bca469c0" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "sender", "type": "address" }, { "name": "receiver", "type": "address" }, { "name": "value", "type": "uint256" }, { "name": "rewardType", "type": "bytes32" }, { "name": "senderMsg", "type": "string" } ], "name": "sendReward", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "to", "type": "address" }, { "name": "value", "type": "uint256" }, { "name": "rewardType", "type": "bytes32" }, { "name": "rewardReasonMsg", "type": "string" } ], "name": "giveReward", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "rewardType", "type": "bytes32" } ], "name": "showAvailReward", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "inputs": [ { "name": "initValue", "type": "uint256", "index": 0, "typeShort": "uint", "bits": "256", "displayName": "init Value", "template": "elements_input_uint", "value": "999999999" }, { "name": "rewardType", "type": "bytes32", "index": 1, "typeShort": "bytes", "bits": "32", "displayName": "reward Type", "template": "elements_input_bytes", "value": "0xabc" } ], "payable": false, "type": "constructor" }, { "payable": false, "type": "fallback" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" }, { "indexed": false, "name": "receiver", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }, { "indexed": false, "name": "rewardType", "type": "bytes32" }, { "indexed": false, "name": "rewardEvent", "type": "string" }, { "indexed": false, "name": "reason", "type": "string" } ], "name": "BroadcastReward", "type": "event" } ].at("0x169E12BD25063AD6b3df3F12444859b998f64a3a");
-
Call contract constant function
myContract.myConstantFunc(param1 [, param2, ...]) hamroCertif.viewCertificateByCourse("0xae4b913898661b4ace005b760ea784423558c87c", "AdvancedBlockchain")
-
Unlock Account for transaction
personal.unlockAccount(<address>) personal.unlockAccount(eth.accounts[0])
-
Call transaction function
myContract.myTransactionFunc.sendTransaction(param1 [, param2, ...], {from: "0x", gasPrice: <price in wei>, [from: "0x", gas: <gas limit to use>]} hamroCertif.assignCertificate.sendTransaction(0xae4b913898661b4ace005b760ea784423558c87c, CertifID", "CourseName", "Today", "SomeDetail", {from: eth.accounts[0], gasPrice: 10000000000})
-
In geth console
loadScript("/path/to/gethcode.js");