├── .gitignore ├── exec.bat ├── password.txt ├── bash-geth-scripts ├── exec.sh ├── geth-testnet.validate.solidity.sh ├── geth-testnet.account.new.sh ├── geth-testnet.account.list.sh ├── geth-testnet.account.update.sh ├── geth-testnet.console.sh ├── geth-testnet.preload.sh ├── geth-dev.dapp.sh ├── geth-testnet.attach.sh ├── geth-testnet.rpc.sh ├── geth-testnet.account.unlock.sh ├── geth-testnet.sh ├── geth-testnet.miner.sh ├── geth-testnet.dapp.sh └── geth-testnet.ROPSTEN-REVIVAL.sh ├── geth-testnet.validate.solidity.bat ├── geth-testnet.account.new.bat ├── geth-testnet.account.list.bat ├── geth-testnet.account.update.bat ├── geth-testnet.console.bat ├── geth-testnet.preload.bat ├── geth-dev.dapp.bat ├── scripts ├── miner.js ├── utils.js ├── personal.sendTransaction.js ├── getSyncing.js ├── isSyncing.js ├── personal.sendTransaction.nonce.js ├── send.unlock.js ├── listenNumEvent.js └── listenEventsExercise.js ├── geth-testnet.rpc.bat ├── geth-testnet.account.unlock.bat ├── geth-testnet.bat ├── web3api ├── ethVersion.js ├── validateSolidity.js └── getAccounts.js ├── geth-testnet.attach.bat ├── geth-testnet.miner.bat ├── solc.sample.bat ├── sol ├── sample.sol └── sample2.sol ├── geth-testnet.dapp.bat ├── README.md ├── geth-testnet.ROPSTEN-REVIVAL.bat └── default.toml /.gitignore: -------------------------------------------------------------------------------- 1 | data 2 | password.txt 3 | temp 4 | compiled 5 | dev 6 | -------------------------------------------------------------------------------- /exec.bat: -------------------------------------------------------------------------------- 1 | geth --exec "loadScript('./web3api/%1')" attach "http://localhost:8545" -------------------------------------------------------------------------------- /password.txt: -------------------------------------------------------------------------------- 1 | password 2 | password 3 | 4 | /** both account 0 & 1 have password set to password ;-) **/ -------------------------------------------------------------------------------- /bash-geth-scripts/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | geth --exec "loadScript('./web3api/%1')" attach "http://localhost:8545" -------------------------------------------------------------------------------- /geth-testnet.validate.solidity.bat: -------------------------------------------------------------------------------- 1 | geth --exec "loadScript('./web3api/validateSolidity.js')" attach "http://localhost:8545" -------------------------------------------------------------------------------- /geth-testnet.account.new.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --datadir "./data" account new -------------------------------------------------------------------------------- /geth-testnet.account.list.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --datadir "./data" account list -------------------------------------------------------------------------------- /geth-testnet.account.update.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --datadir "./data" account "0" -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.validate.solidity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | geth --exec "loadScript('./web3api/validateSolidity.js')" attach "http://localhost:8545" -------------------------------------------------------------------------------- /geth-testnet.console.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --verbosity "0" --datadir "./data" console 4 | -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.account.new.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --datadir "./data" account new -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.account.list.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --datadir "./data" account list -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.account.update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --datadir "./data" account "0" -------------------------------------------------------------------------------- /geth-testnet.preload.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --verbosity "0" --datadir "./data" --preload "./scripts/utils.js" console -------------------------------------------------------------------------------- /geth-dev.dapp.bat: -------------------------------------------------------------------------------- 1 | Rem Creates a private DEV Network 2 | 3 | geth --dev --datadir "./data" --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.console.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --verbosity "0" --datadir "./data" console 5 | -------------------------------------------------------------------------------- /scripts/miner.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Shows the use of various methods on miner object 3 | */ 4 | miner.setEtherbase(personal.listAccounts[1]) 5 | 6 | miner.setExtra("acloudfan.com #2 Account") 7 | 8 | miner.start() -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.preload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --verbosity "0" --datadir "./data" --preload "./scripts/utils.js" console -------------------------------------------------------------------------------- /geth-testnet.rpc.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net" --rpccorsdomain "*" --datadir "./data" -------------------------------------------------------------------------------- /geth-testnet.account.unlock.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | geth --testnet --verbosity "0" --datadir "./data" --exec "loadScript('./scripts/send.unlock.js')" --unlock "0" console -------------------------------------------------------------------------------- /bash-geth-scripts/geth-dev.dapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Creates a private DEV Network 4 | 5 | geth --dev --datadir "./data/dev" --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.attach.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This command is good on windows 3 | # geth attach "//./pipe/geth.ipc" 4 | 5 | # On UNIX/Linux/Mac the geth.ipc is created under the data directory 6 | geth attach "./data/geth.ipc" -------------------------------------------------------------------------------- /geth-testnet.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | Rem To connect to RINKEBY replace --testnet with --rinkeby 3 | 4 | geth --testnet --identity "MyTestNode" --datadir "./data" --verbosity "4" --fast 5 | -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.rpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net" --rpccorsdomain "*" --datadir "./data" -------------------------------------------------------------------------------- /web3api/ethVersion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Temp Test 3 | * exec ethVersion 4 | */ 5 | 6 | web3.version 7 | 8 | console.log("api=",web3.version.api) 9 | console.log("network=",web3.version.network) 10 | console.log("ethereum=",web3.version.ethereum) -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.account.unlock.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | geth --testnet --verbosity "0" --datadir "./data" --exec "loadScript('./scripts/send.unlock.js')" --unlock "0" console -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | # To connect to RINKEBY replace --testnet with --rinkeby 4 | 5 | geth --testnet --identity "MyTestNode" --datadir "./data" --verbosity "4" --fast 6 | -------------------------------------------------------------------------------- /geth-testnet.attach.bat: -------------------------------------------------------------------------------- 1 | Rem This command is good on windows 2 | geth attach "//./pipe/geth.ipc" 3 | 4 | Rem On UNIX/Linux/Mac the geth.ipc is created under the data directory 5 | Rem To use comment command above & uncomment command below 6 | 7 | Rem geth attach "./data/geth.ipc" -------------------------------------------------------------------------------- /geth-testnet.miner.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | Rem Do not forget to change the etherbase account 4 | 5 | geth --testnet --datadir "./data" --mine --minerthreads "4" --extradata "ACloudFan.com" --etherbase "0x09f651352530526d2a78ecb268ec7f0a60d1b219" console 6 | -------------------------------------------------------------------------------- /scripts/utils.js: -------------------------------------------------------------------------------- 1 | // Set the primary account 2 | primary="value not set"; 3 | 4 | // Set the initial balance of primary account 5 | primaryBalance="value not set"; 6 | 7 | // Do something 8 | myUtility = function(){ 9 | console.log("Add calls to eth/miner/admin ....."); 10 | return "done"; 11 | } -------------------------------------------------------------------------------- /solc.sample.bat: -------------------------------------------------------------------------------- 1 | Rem This shows how to use the solidity compiler on windows 2 | 3 | Rem c:\Solidity\solc --abi ./sol/sample.sol > ./sol/sample.abi.json 4 | 5 | Rem c:\Solidity\solc --bin ./sol/sample.sol > ./sol/sample.bin 6 | 7 | Rem c:\Solidity\solc --combined-json abi,bin ./sol/sample.sol > ./sol/sample.json -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.miner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | # Do not forget to change the etherbase account 5 | 6 | geth --testnet --datadir "./data" --mine --minerthreads "4" --extradata "ACloudFan.com" --etherbase "0x09f651352530526d2a78ecb268ec7f0a60d1b219" console 7 | -------------------------------------------------------------------------------- /web3api/validateSolidity.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Cimpiles the solidity contract code to validate the Solidity compiler setup 3 | */ 4 | var sampleSolidityCode = "pragma solidity ^0.4.5; contract MyContract { uint num;event NumberSetEvent(address indexed caller, uint oldNum, uint newNum);function getNum() returns (uint n) {return num;} function setNum(uint n) {uint old = num;num=n;NumberSetEvent(msg.sender,old,num);}function MyContract(uint x){num=x;}}" 5 | 6 | 7 | var contract = eth.compile.solidity(sampleSolidityCode) 8 | 9 | console.log(contract) -------------------------------------------------------------------------------- /sol/sample.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | contract sample { 3 | 4 | uint num; 5 | 6 | event NumberSetEvent(address indexed caller, bytes32 indexed oldNum, bytes32 indexed newNum); 7 | 8 | function getNum() public returns (uint n) { 9 | return num; 10 | } 11 | 12 | function setNum(uint n) public { 13 | uint old = num; 14 | num=n; 15 | NumberSetEvent(msg.sender,bytes32(old),bytes32(num)); 16 | } 17 | 18 | function sample(uint x) public { 19 | num=x; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /geth-testnet.dapp.bat: -------------------------------------------------------------------------------- 1 | Rem DO NOT FORGET TO REPLACE --testnet if you are using --dev 2 | 3 | Rem Starting v1.6 geth the --solc option is NO MORE SUPPORTED :( 4 | 5 | rem MAKE SURE SOLIDITY Path is Correct 6 | rem On LINUX/MAC you may use $ which solc to find path to the compiler 7 | rem geth --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --datadir "./data" --solc "c:/Solidity/solc" --testnet 8 | 9 | rem By default the syncmode is fast 10 | 11 | geth --testnet --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --datadir "./data" -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.dapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DO NOT FORGET TO REPLACE --testnet if you are using --dev 3 | 4 | # Starting v1.6 geth the --solc option is NO MORE SUPPORTED :( 5 | 6 | # MAKE SURE SOLIDITY Path is Correct 7 | # On LINUX/MAC you may use $ which solc to find path to the compiler 8 | # geth --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --datadir "./data" --solc "c:/Solidity/solc" --testnet 9 | 10 | # By default the syncmode is fast 11 | geth --testnet --rpc --rpcaddr "localhost" --rpcport "8545" --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --datadir "./data" -------------------------------------------------------------------------------- /scripts/personal.sendTransaction.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Shows the use of personal.sendTransaction 3 | * 4 | * To run this script: 5 | * 1. Attach to the running geth node 6 | * 2. Type the lines (or cut/paste) to interactive console OR 7 | * 2. Type & hit enter >> loadScript("./scripts/sendTransaction.js") 8 | */ 9 | from = personal.listAccounts[0] 10 | to = personal.listAccounts[1] 11 | 12 | // Convert 0.001 ethers to Wei 13 | amount = web3.toWei(0.001,"ether"); 14 | 15 | // Transaction object 16 | txn = { 17 | from: from, 18 | to: to, 19 | amount: amount 20 | } 21 | 22 | // Send the transaction 23 | addr = personal.sendTransaction(txn, "password") 24 | 25 | // Print to cnsole 26 | console.log('Transaction created: ', addr) -------------------------------------------------------------------------------- /web3api/getAccounts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Get the accounts from the connected node 3 | * ASync web3.eth.accounts 4 | * Sync web3.eth.getAccounts(callback) 5 | * 6 | * To execute this script in console 7 | * > exec getAccounts.js 8 | */ 9 | 10 | 11 | accounts = web3.eth.accounts 12 | 13 | //console.log("Sync eth.accounts=", JSON.stringify(accounts)) 14 | 15 | console.log('\nSync Call') 16 | console.log("Result=",JSON.stringify(accounts)) 17 | 18 | // Async call 19 | web3.eth.getAccounts(function(error, result){ 20 | console.log("\nAsync Call"); 21 | if(error){ 22 | console.log('Error=',JSON.stringify(error)); 23 | } else { 24 | console.log('Result=',JSON.stringify(result)); 25 | } 26 | }); -------------------------------------------------------------------------------- /sol/sample2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | contract MyContract { 3 | 4 | uint num; 5 | 6 | event NumberSetEvent(address indexed caller, uint oldNum, uint newNum); 7 | event NumberDoubled(address indexed caller,uint oldNum, uint newNum); 8 | 9 | function getNum() public returns (uint) { 10 | return num; 11 | } 12 | 13 | function setNum(uint newNum) public { 14 | uint old = num; 15 | num=newNum; 16 | NumberSetEvent(msg.sender,old,num); 17 | } 18 | 19 | function setDouble() public { 20 | uint old = num; 21 | num=n; 22 | NumberDoubled(msg.sender,old,num); 23 | } 24 | 25 | function MyContract(uint x) public { 26 | num=x; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | http://www.acloudfan.com 2 | 3 | raj@acloudfan.com 4 | 5 | # Hands on Blockchain for Developers and Arhitects 6 | 7 | Part of a course. 8 | 9 | On Windows: Run .bat files to launch geth 10 | 11 | On Linux/Mac: The shell scripts are under bash subfolder 12 | - to run them you must prefix the file with the shell command ie: sh geth-testnet.sh 13 | 14 | *OR* Simply copy and paste the commands from the files to the terminal 15 | 16 | To use the commands: 17 | 18 | 1. Create a local directory 19 | 2. Open a terminal window 20 | > geth-testnet 21 | This would setup the data directories for chain data ./data 22 | 3. Open a new terminal window 23 | > geth-testnet.attach 24 | This would open a console to the running geth 25 | 26 | Try out the other files to learn geth CLI 27 | 28 | PS: Ensure terminal windows are open with the current directory as the one that you created 29 | 30 | -------------------------------------------------------------------------------- /scripts/getSyncing.js: -------------------------------------------------------------------------------- 1 | /** 2 | * web3.eth.getSyncing 3 | * Callback receieves either a sync object, 4 | * when the node is syncing or false. 5 | * 6 | * Script for demonstrating the isSync functionality 7 | * 8 | * To Test: 9 | * 1) Launch geth 10 | * 2) Attach to geth 11 | * 3) Copy paste the code below in attached console 12 | * 13 | * Repeat 14 | * 4) Kill geth & start 15 | * 5) In attached console you would see change in SYNCHING messages 16 | */ 17 | 18 | web3.eth.getSyncing(function(error, sync){ 19 | if(!error) { 20 | // sync = boolean OR object 21 | if(sync === true) { 22 | // true receieved 23 | console.log("SYNCHING: true") 24 | } else if(sync) { 25 | // object received 26 | console.log("SYNCHING: ", sync); 27 | } else { 28 | // false received 29 | console("SYNCHING: false") 30 | } 31 | } else { 32 | console.log("SYNCHING: ERROR"); 33 | console.log(error); 34 | } 35 | }); -------------------------------------------------------------------------------- /scripts/isSyncing.js: -------------------------------------------------------------------------------- 1 | /** 2 | * web3.eth.isSyncing 3 | * This convenience function calls the callback everytime a sync 4 | * starts, updates and stops. 5 | * 6 | * Script for demonstrating the isSync functionality 7 | * 8 | * To Test: 9 | * 1) Launch geth 10 | * 2) Attach to geth 11 | * 3) Copy paste the code below in attached console 12 | * 13 | * Repeat 14 | * 4) Kill geth & start 15 | * 5) In attached console you would see change in SYNCHING messages 16 | */ 17 | 18 | web3.eth.isSyncing(function(error, sync){ 19 | if(!error) { 20 | // sync = boolean OR object 21 | if(sync === true) { 22 | // true receieved 23 | console.log("SYNCHING: true") 24 | } else if(sync) { 25 | // object received 26 | console.log("SYNCHING: ", sync.currentBlock); 27 | } else { 28 | // false received 29 | console("SYNCHING: false") 30 | } 31 | } else { 32 | console.log("SYNCHING: ERROR"); 33 | console.log(error); 34 | } 35 | }); -------------------------------------------------------------------------------- /scripts/personal.sendTransaction.nonce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Shows the use of personal.sendTransaction with nonce 3 | * ** Nonce is a running counter associated with the account 4 | * ** Every transaction has a nonce 5 | * ** If the nonce is skipped then the transaction is set aside i.e., goes to the queue 6 | * ** This queue is on the geth client and a maximum of 64 transactions can be queued (per doc) 7 | * ** This is part of the ethereum protocol 8 | * 9 | * To run this script: 10 | * 1. Attach to the running geth node 11 | * 2. Type the lines (or cut/paste) to interactive console OR 12 | * 2. Type & hit enter >> loadScript("./scripts/personal.sendTransaction.nonce.js") 13 | */ 14 | from = personal.listAccounts[0] 15 | to = personal.listAccounts[1] 16 | 17 | // Convert 0.001 ethers to Wei 18 | amount = web3.toWei(0.001,"ether"); 19 | 20 | // Transaction object 21 | 22 | // Set the nonce higher than the max nonce for your account 23 | my_nonce=10 24 | // Set the data string in hex 25 | my_data="0xABCDEF" 26 | 27 | txn = { 28 | from: from, 29 | to: to, 30 | amount: amount, 31 | nonce: my_nonce, 32 | data: my_data 33 | } 34 | 35 | // Send the transaction 36 | addr = personal.sendTransaction(txn, "password") 37 | 38 | // Print to cnsole 39 | console.log('Transaction created: ', addr) -------------------------------------------------------------------------------- /geth-testnet.ROPSTEN-REVIVAL.bat: -------------------------------------------------------------------------------- 1 | Rem NOT APPLICABLE for the --dev 2 | 3 | Rem Clean the data directory before running the command | you may use geth --data removedb 4 | Rem #1 Try this command first - if it does not work try #2 5 | geth --identity "MyTestNode" --datadir "./data" --testnet --fast --bootnodes "enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303" 6 | 7 | Rem #2 Two step process 8 | Rem Step 1 - run the following command (Needs to be done once for initial sync) 9 | Rem $ geth --testnet --fast --nodiscover 10 | 11 | Rem Step 2 - attach to geth instance - Run following commands in the console 12 | Rem > admin.addPeer('enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303') 13 | Rem > admin.addPeer('enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303') 14 | 15 | Rem AFTER Synchronozation is complete = You can use the regular script : geth-testnet.DAPP 16 | 17 | -------------------------------------------------------------------------------- /bash-geth-scripts/geth-testnet.ROPSTEN-REVIVAL.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # NOT APPLICABLE for the --dev 3 | 4 | # Clean the data directory before running the command | you may use geth --data removedb 5 | # #1 Try this command first - if it does not work try #2 6 | 7 | geth --identity "MyTestNode" --datadir "./data" --testnet --fast --bootnodes "enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303" 8 | 9 | # #2 Two step process 10 | # Step 1 - run the following command (Needs to be done once for initial sync) 11 | # $ geth --testnet --fast --nodiscover 12 | 13 | # Step 2 - attach to geth instance - Run following commands in the console 14 | # > admin.addPeer('enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303') 15 | # > admin.addPeer('enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303') 16 | 17 | # AFTER Synchronozation is complete = You can use the regular script : geth-testnet.DAPP 18 | 19 | -------------------------------------------------------------------------------- /scripts/send.unlock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Demo script that initiates a transaction to send ethers 3 | * from account at index=0 to account on index=1 4 | * If the account is not explicitly unlocked the transaction will fail 5 | * To run the script successfully use the --unlock option 6 | * 7 | * Following will fail because the account is locked 8 | * geth --verbosity "0" --datadir "./data" --testnet --exec "loadScript('./scripts/send.unlock.js')" attach 9 | * 10 | * Following will go through 11 | * Replace --testnet with --rinkeby or --networkid depending on your needs 12 | * geth --unlock "" --password "" --verbosity "0" --datadir "./data" --testnet --exec "loadScript('./scripts/send.unlock.js')" attach 13 | * 14 | * Check balance 15 | * 16 | */ 17 | 18 | //transferEthers = function(){ 19 | sender = personal.listAccounts[0]; // Same as eth.coinbase 20 | receiver = personal.listAccounts[1]; 21 | 22 | // Send 0.1 ether from sender to receiver account 23 | // The value to be trasferred should be in wei 24 | amount = web3.toWei(0.001,"ether"); 25 | 26 | // Call send to transfer 0.1 ether from account 0 to account 1 27 | 28 | addr = eth.sendTransaction({from:sender, to:receiver, value: amount}) 29 | 30 | console.log("Address=",addr); 31 | 32 | // In a single line 33 | // personal.unlockAccount(eth.coinbase,"password") 34 | // eth.sendTransaction({from:personal.listAccounts[0], to:personal.listAccounts[1], value: web3.toWei(0.1,"ether")}) 35 | 36 | // web3.eth.sendTransaction({from:sender, to:receiver, value: amount},function(error, result){ 37 | // console.log("Err=",error); 38 | // console.log("Result=",result) 39 | // }) 40 | //} 41 | -------------------------------------------------------------------------------- /scripts/listenNumEvent.js: -------------------------------------------------------------------------------- 1 | // 1. Create the contract object by passing the ABI Definition of sample contract 2 | // var contractObject = web3.eth.contract([{"constant":false,"inputs":[],"name":"getNum","outputs":[{"name":"n","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"n","type":"uint256"}],"name":"setNum","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"x","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"caller","type":"address"},{"indexed":true,"name":"oldNum","type":"bytes32"},{"indexed":true,"name":"newNum","type":"bytes32"}],"name":"NumberSetEvent","type":"event"}]) 3 | var contractObject = web3.eth.contract(COPY & PASTE ABI DEFINITION FROM WORKBENCH) 4 | 5 | 6 | // 2. Create an instance of the contract by passing address of the contract 7 | // Copy the address from the TheDapps.com workbench app if that is what you used to deploy 8 | // COPY THE ADDRESS of your deployed contract 9 | contractInstance = contractObject.at("COPY PASTE ADDRESS OF CONTRACT - HERE"); 10 | 11 | // This is the ASynchronous version 12 | // contractObject.at("0x66027c218cb47fe81ab80075a073c72e99808745", function(error, result){contractInstance=result});;//PASTE ADDRESS HERE") 13 | 14 | // 3. Make a get Call 15 | contractInstance.getNum.call() 16 | 17 | // 4. Lets setup a event watcher 18 | // Watcher will recieve an event every time the setNum is called with num=7 19 | myEventCallbackFunc = function(error, result){console.log("Event for num Receieved",JSON.stringify(result))} 20 | event = contractInstance.NumberSetEvent({"newNum":"0x0000000000000000000000000000000000000000000000000000000000000007"},{"fromBlock": "latest"}) 21 | event.watch(myEventCallbackFunc) 22 | 23 | 24 | contractInstance.setNum.sendTransaction(5,{"from":eth.coinbase}); 25 | 26 | // 5. Stop watching 27 | event.stopWatching() 28 | 29 | 30 | -------------------------------------------------------------------------------- /scripts/listenEventsExercise.js: -------------------------------------------------------------------------------- 1 | // 1. Create the contract object by passing the ABI Definition of sample contract 2 | // var contractObject = web3.eth.contract([{"constant":false,"inputs":[],"name":"getNum","outputs":[{"name":"n","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"n","type":"uint256"}],"name":"setNum","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"x","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"caller","type":"address"},{"indexed":true,"name":"oldNum","type":"bytes32"},{"indexed":true,"name":"newNum","type":"bytes32"}],"name":"NumberSetEvent","type":"event"}]) 3 | 4 | 5 | var contractObject = web3.eth.contract(COPY & PASTE ABI DEFINITION FROM WORKBENCH) 6 | 7 | 8 | // 2. Create an instance of the contract by passing address of the contract 9 | // Copy the address from the TheDapps.com workbench app if that is what you used to deploy 10 | // COPY THE ADDRESS of your deployed contract 11 | 12 | 13 | contractInstance = contractObject.at("COPY PASTE ADDRESS OF CONTRACT - HERE"); 14 | 15 | // This is the ASynchronous version 16 | // contractObject.at("0x66027c218cb47fe81ab80075a073c72e99808745", function(error, result){contractInstance=result});;//PASTE ADDRESS HERE") 17 | 18 | // 3. Make a get Call 19 | 20 | 21 | contractInstance.getNum.call() 22 | 23 | // 4. Lets setup a event watcher 24 | // Watcher will recieve an event every time the setNum is called with num=7 25 | 26 | myEventCallbackFunc = function(error, result){console.log("Event for num Receieved",JSON.stringify(result))} 27 | 28 | event = contractInstance.NumberSetEvent({"newNum":"0x0000000000000000000000000000000000000000000000000000000000000007"},{"fromBlock": "latest"}) 29 | 30 | event.watch(myEventCallbackFunc) 31 | 32 | // 5. Use the workbench DAPP to send transaction OR use the following 33 | 34 | contractInstance.setNum.sendTransaction(5,{"from":eth.coinbase}); 35 | 36 | // 6. Stop watching 37 | 38 | event.stopWatching() 39 | -------------------------------------------------------------------------------- /default.toml: -------------------------------------------------------------------------------- 1 | [Eth] 2 | NetworkId = 3 3 | SyncMode = "fast" 4 | LightPeers = 20 5 | DatabaseCache = 128 6 | GasPrice = 18000000000 7 | EthashCacheDir = "ethash" 8 | EthashCachesInMem = 2 9 | EthashCachesOnDisk = 3 10 | EthashDatasetDir = "C:\\Users\\Rajeev\\AppData\\Ethash" 11 | EthashDatasetsInMem = 1 12 | EthashDatasetsOnDisk = 2 13 | EnablePreimageRecording = false 14 | 15 | [Eth.TxPool] 16 | NoLocals = false 17 | Journal = "transactions.rlp" 18 | Rejournal = 3600000000000 19 | PriceLimit = 1 20 | PriceBump = 10 21 | AccountSlots = 16 22 | GlobalSlots = 4096 23 | AccountQueue = 64 24 | GlobalQueue = 1024 25 | Lifetime = 10800000000000 26 | 27 | [Eth.GPO] 28 | Blocks = 10 29 | Percentile = 50 30 | 31 | [Shh] 32 | MaxMessageSize = 1048576 33 | MinimumAcceptedPOW = 2e-01 34 | 35 | [Node] 36 | DataDir = "C:\\Users\\Rajeev\\AppData\\Roaming\\Ethereum" 37 | IPCPath = "geth.ipc" 38 | HTTPPort = 8545 39 | HTTPModules = ["net", "web3", "eth", "shh"] 40 | WSPort = 8546 41 | WSModules = ["net", "web3", "eth", "shh"] 42 | 43 | [Node.P2P] 44 | MaxPeers = 25 45 | NoDiscovery = false 46 | DiscoveryV5Addr = ":30304" 47 | BootstrapNodes = ["enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303", "enode://3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99@13.93.211.84:30303", "enode://78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d@191.235.84.50:30303", "enode://158f8aab45f6d19c6cbf4a089c2670541a8da11978a2f90dbf6a502a4a3bab80d288afdbeb7ec0ef6d92de563767f3b1ea9e8e334ca711e9f8e2df5a0385e8e6@13.75.154.138:30303", "enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303", "enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303"] 48 | BootstrapNodesV5 = ["enode://0cc5f5ffb5d9098c8b8c62325f3797f56509bff942704687b6530992ac706e2cb946b90a34f1f19548cd3c7baccbcaea354531e5983c7d1bc0dee16ce4b6440b@40.118.3.223:30305", "enode://1c7a64d76c0334b0418c004af2f67c50e36a3be60b5e4790bdac0439d21603469a85fad36f2473c9a80eb043ae60936df905fa28f1ff614c3e5dc34f15dcd2dc@40.118.3.223:30308", "enode://85c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaf@40.118.3.223:30309"] 49 | StaticNodes = [] 50 | TrustedNodes = [] 51 | ListenAddr = ":30303" 52 | EnableMsgEvents = false 53 | --------------------------------------------------------------------------------