3. Go to online compiler , copy compile->Details->Web3Deploy -- Sandeep Kanao
4. Execute each using white lines removal
5. Call contract function as
greeter.greet(); -- contract.function();
eth-private-blockchain is a simple tool that allows you to quickly setup a three-node private Ethereum network running locally on your personal computer (Windows 7). The tool makes initializing, starting, and connecting nodes fast and easy. The network comes with three pre-made identities (Amar, Akbar, and Anthony) and a tutorial that walks you through simple actions like mining and transferring Ether, and culminates with the deployment and execution of a simple smart contract`. Source code is available on GIT.
Prerequisites: Make sure geth is installed and in the $PATH. geth is a golang implementation of the Ethereum protocol and provides command line tools for interacting with the Ethereum network. You can download pre-compiled binaries or install from Homebrew or source using the installation instructions.
The base denomination of currency on the (Sandeep Kanao) Ethereum network is the Ether. However, since most actions on the network require just fractions of an Ether, we'll be referring to various denominations of Ether throughout the tutorial (e.g., Wei, GWei, Szabo, etc.). This site gives an overview of the various denominations, and allows you to convert between them.
Identities
The private network comes with three identities (each secured with foobar123 as the password):
Each user's identity is stored in ./[NAME]/keystore/UTC-....
Initializing From Genesis Block
Since we're bootstrapping our own private chain, we'll need a genesis block. The definition for our block will be stored in genesis.json. Both Amar and Akbar's addresses are pre-allocated with 1 Ether (or 1e+18 Wei). Just run:
→ ./eth-private-blockchain init
Note: Tearing down your private network and resetting all account balances is easy. Just run:
→ ./eth-private-blockchain clean
Running a Private Test Net
Nodes for amar, akbar, or anthony can be started easily with the start action of the convenience script:
→ ./eth-private-blockchain start amar
Starting node for amar on port: 40301, RPC port: 8101. Console logs sent to ./amar/console.log
Welcome to the Geth JavaScript console!
This starts a running Ethereum node, loads whatever identity you specified on the command line, and starts a console where you can begin interacting with your private net. The console itself is a Javascript REPL with all of the commands you need to begin working with Ethereum preloaded. You can check out all of the available commands here.
The first thing you can do is check Amar's balance, which should show exactly 1e+18 Wei (1 Ether).
# As amar:
> eth.getBalance("0xdda6ef2ff259928c561b2d30f0cad2c2736ce8b6")
1000000000000000000
For convenience, the addresses for amar, akbar, and anthony have been aliased to variables.
Get [enode] for Amar, Akbar and Anthony, to connect to the peers.
As Amar
admin.nodeInfo.enode
Take this identifier and use it to connect Akbar's node to Amar (make sure to start Akbar's node with: ./eth-private-net start Akbar):
# As akbar:
> admin.peers
[]
admin.addPeer("enode://f15b1...@[::]:40301?discport=0")
Start nodes for amar, akbar, and anthony (using `eth-private-net start [amar | akbar | anthony]`), and connect the three nodes using:
Add Amar to Akbar
Add Amar to Anthony
Add Akbar to Anthony
> admin.peers
[{
...
..
}
}]
Mining - Sandeep Kanao
The console allows you to begin mining on our private network easily. Simply execute miner.start():
Now that we've mined a few blocks, let's try transferring some Ethereum. Let's start from a clean network. Shutdown any running nodes by typing exit at the console prompt. Clean and reinitialize the network by executing:
## Deploying and Running Smart Contracts
One of the most interesting features of the Ethereum blockchain is the ability to deploy and run [smart contracts](https://en.wikipedia.org/wiki/Smart_contract) on the blockchain. In this section, we'll go through a simple example of writing, deploying, and running a smart contract called `Freecandy`.
### FreeCandy - A simple, Smart Contract
I've included a sample contract called `FreeCandy` in [`solidity/FreeCandy.sol`]. The contract itself is simple and written in [Solidity](https://en.wikipedia.org/wiki/Solidity), a statically-typed language for writing smart contracts. It allows anybody on the Ethereum network to send the contract holder some money. Though it is simple, it illustrates some basic concepts around using smart contracts to send Ether.
To deploy a Solidity contract, you'll need to compile it into an [Application Binary Interface (ABI)] and Ethereum Virtual Machine (EVM) [bytecode]. The ABI itself is a bit of JSON that defines the contract's interface--- e.g., what methods it exposes or the types of its arguments. The bytecode is a hex-encoded string that allows the contract to be run on the Ethereum Virtual Machine (EVM) when the contract is called.
I've pre-compiled FreeCandy's ABI and bytecode (both in `solidity/`) using [`sol-js`](https://github.com/ethereum/solc-js) and wrapped both in a simple javascript file that allows easy use inside the geth console:
### Deploying
Note: Make sure you unlock the accounts before deploying a contract or executing calls against it.
Unlock accounts (amar, akbar and anthony)
> personal.unlockAccount(eth.coinbase)
**make sure that a miner is running** (in these examples, anthony is the sole running miner).
Suppose Amar wishes to deploy `FreeCandy` to allow anybody to send him some Ether. First, he'll need to prepare a transaction specifying the contract's compiled bytecode as data. We'll also provide 200,000 gas to pay for the deployment, and use `eth.estimateGas(...)` to check that our supplied gas is sufficient to pay for the contract's deployment:
Next, we'll create an instance of the contract from its ABI, and deploy it using the transaction. We can then obtain the deployed contract's address from the receipt (**Note:** The address of the deployed contract is `0x48c1bd...` in the example, but will be different for you):
As amar:
var freeCandyContract = eth.contract(freeCandyAbi) undefined
var freeCandyInstance = freeCandyContract.new(deployTxn) undefined
var receipt = eth.getTransactionReceipt(freeCandyInstance.transactionHash) undefined
We see that we used 165,814 gas in the deployment--- just 1 off of our initial estimate! After deployment, Amar's account balance decreased by 2,984,652 Gwei (1 Gwei = 1 Shannon = 1 Nano Ether), which is just the cost of 165,814 gas as the prevailing price of 18 Gwei.
### Using FreeCandy to Transfer Money
Now that our contract is deployed, let's have Akbar use it to send some money to Amar via the contract. To do so, Akbar will take the compiled ABI and bind it to the deployed contract's address. Akbar can then use this contract to call the `.gimmeMoney` method, sending 100 Finneys (1 Finney = 1 milliEther) to the contract owner (Amar):
As akbar:
loadScript('solidity/FreeCandy.sol.js') true
var freeCandyContract = eth.contract(freeCandyAbi) undefined
var freeCandyDeployed = freeCandyContract.at("0x48c1bdb954c945a57459286719e1a3c86305fd9e") undefined
Checking our account balances after the transaction shows that Amar's account has indeed increased by 100 Finneys, while Akbar's has decreased by about 100.56 Finneys. Again, the discrepancy is due to the gas cost of executing the smart contract. In this case, the cost (at the prevailing gas price) was 30,979 gas:
### Events on Smart Contracts
The last concept we'll cover are events. Each time money is successfully sent, the contract emits an [event]. The following calls will allow us examine these events in greater detail.
var outputEvent = function (e, result) { console.log(JSON.stringify(result)); } undefined