Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
Ananthan R edited this page May 29, 2018 · 7 revisions

AgroChain

Agricultural Supply Chain Dapp With Micro-Finance

Truffle Installation:

The following installation code was tested on Ubuntu version 16.04.

Step 1: Install node and npm:

Windows:

  1. https://nodejs.org/en/download/
  2. Download the .exe and install

Linux:

  1. sudo apt-get install curl
  2. curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
  3. sudo apt-get install -y nodejs

Step 2: Install Truffle

sudo npm install -g truffle  

Documentation: http://truffleframework.com/docs/getting_started/installation

Step 3: Install Testrpc

npm install -g ethereumjs-testrpc

GitHub repository: https://github.com/ethereumjs/testrpc

Setting up an example application:

Step 4: Make a new project directory: eg. mkdir TruffleProject

Step 5: Run this command from the project directory: truffle init webpack

Step 6: Start testrpc by the running the command line: testrpc

Step 7: Run commands: truffle compile and then truffle migrate

Step 8: npm run dev to build the app and serve it on http://localhost:8080

Documentation: https://github.com/trufflesuite/truffle-init-webpack

Creating a private Blockchain using geth

Step 9: Install geth

Windows: Download the latest stable binary from

https://geth.ethereum.org/downloads/

 extract it or download the zip file, 
 extract geth.exe from zip, open a command terminal and type: 
 chdir <path to extracted binary>
 open geth.exe

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

Step 10: Creating a private network using geth: Connecting to a private test net:

Sometimes we might not want to connect to the live public network; instead we can choose to create our own private testnet. This is very useful if we don't need to test public contracts and want just to try- or develop on the technology. Since we are the only member of our private network we are responsible for finding all blocks, validating all transactions and executing all smart contracts. This makes development cheaper and easier as we have the ability to flexibly control the inclusion of transactions in our own personal blockchain.

Create a new directory eg: GethProject

Step 11: cd GethProject mkdir datadir create a new file 'genesis.json' inside GethProject

     An example Genesis.json (Copy this to the genesis file) :
     {
         "config": {
             "chainId": 15,
             "homesteadBlock": 0,
             "eip155Block": 0,
             "eip158Block": 0
         },
         "difficulty": "200000000",
         "gasLimit": "2100000",
         "alloc": {`
             "7df9a875a174b3bc565e6424a0050ebc1b2d1d81": { "balance": "300000" },
             "f41c74c9ae680c1aa78f42e5647a62f353b7bdd2": { "balance": "400000" }
         }
     }

Step 12:

geth --datadir /home/iiitmk/GethProject/datadir init /home/iiitmk/GethProject/genesis.json

The above command initialises the private chain with the genesis file and chain data can be found on the datadir folder

geth --networkid 1234 --datadir /home/iiitmk/GethProject/datadir console

The above command starts geth as a private blockchain and starts the geth console.

More links:

https://lightrains.com/blogs/setup-local-ethereum-blockchain-private-testnet	   
https://www.ethereum.org/cli	   
https://souptacular.gitbooks.io/ethereum-tutorials-and-tips-by-hudson/content/private-chain.html
https://github.com/ethereum/go-ethereum/wiki/Private-network

Creating a password file to unlock geth accounts while starting geth and using mine.js to customize the proof of work mining

Step 13: We can now create an example private chain using a custom genesis file and data directory. (refer steps 10 to 12) See example:

geth --datadir "/home/iiitmk/GethProject/datadir" init "/home/iiitmk/GethProject/genesis.json"

Next to run the geth command line console:

geth --networkid 1234 --datadir "/home/iiitmk/GethProject/datadir" --port 30303 --rpc --rpcport 8545 --rpcaddr localhost --rpccorsdomain="http://localhost:8080" --nodiscover --shh --rpcapi "eth,web3,shh" console

Step 14: Create a new account in geth using geth console:

personal.newAccount("yourpassword");

Example result:

0xb859a10767e0c631e09a997ec731c2edfb2ac693

Step 15: Create a password file: Create an empty document and add your accounts password to it (one password per row) and save it inside the data directory.

Step 16: Copy the mine.js file and place it inside your data directory. This file enables the chain to run the proof of work mining only when a transaction has arrived. Thus it enables a customized mining for development environment. To get the mine.js file visit:

https://mega.nz/#!4JJh2IjD!z1nvZxUrbPDyKYi9GIHwaN41uuds6RlQOr4JzOX3aic

Step 17: To run the private chain:

geth --datadir "/home/iiitmk/GethProject/datadir" --password "/home/iiitmk/GethProject/datadir/password" --port 30303 --rpc --rpcport 8545 --rpcaddr localhost --rpccorsdomain="http://localhost:8080" --nodiscover --maxpeers 25 --mine --shh --rpcapi "eth,web3,shh" --unlock=0x6a056d887825bda6dfa4435805b6d49fb3afc6d0 js "/home/iiitmk/GethProject/datadir/mine.js"

Note: Here --unlock="your first accounts public id", "second account id" and --password="path to password file"

Step 18: Finally, to attach a second command line to geth console:

geth attach ipc://home/iiitmk/GethProject/datadir/geth.ipc