KEMBAR78
gething started - ethereum & using the geth golang client | PDF
gething started
geth=
golang + blockchain + ethereum
sathishvj
Talk Set: Utils and Projects in Go
● Identify interesting tools and projects in Go
○ As opposed to focusing only on the language
● Highlight big/awesome projects and inform
dev audience it was written in Go
● Encourage open source contribution in Go
● Promote daily use tools written in Go
● SFO searches Go; BLR searches JSP
○ Courtesy: stackoverflow research data
● For orgs shifting to Go, make available a
wider developer pool
Blockchain
Intro quick highlights of blockchain,
ethereum
Blockchain
A blockchain is a distributed database
that maintains a continuously growing
list of records called blocks secured from
tampering and revision. Each block
contains a timestamp and a link to a
previous block.
4See my more elaborate talk at GDG DevFest: slideshare.net/SathishVJ/blockchain-bitcoin
Transactions & Blocks
5
Bitcoin
A distributed, decentralized,
digital cryptocurrency that relies
on Blockchain technology.
6
Ethereum
A blockchain-based distributed
computing platform, featuring smart
contract functionality. It provides a
decentralized virtual machine that
can execute peer-to-peer contracts
using a cryptocurrency called ether.
7
Blockchain : Bitcoin : Ethereum
Core
Tech
Gen 1: Special
Purpose Apps
Next Gen:
Platform for Apps
8
Ethereum
Clients What all are available?
Ethereum Clients
● Multiple clients based on Ethereum Yellow Paper
● In Go, Rust, C++, Python, JavaScript, etc.
● The Go based Ethereum client is called geth
● Got a dedicated website recently
○ Geth.ethereum.org
● Can also be used a library
○ In Mobiles
○ https://ethereum.karalabe.com/talks/2016-devcon.html
Geth Usage
● Largest ethereum client is the go client,
geth
● Most versions used are up to date, >
1.5.3
Miners in India
● About 100 nodes
● Mostly using geth
Ethereum &
DApps
Architecture Components - Current and Future
Ethereum, Swarm, Whisper
● Contracts: decentralized logic
● Swarm: decentralized storage
● Whisper: decentralized
messaging
Tech Components
● DApp: Distributed Application
● Solidity: a language to write contracts on ethereum
● web3: a library to interact with ethereum blockchain (web3.eth). Contains
other objects like (web3.shh for Whisper)
● Import web3.js in your browser to interact with the blockchain
● General term web3
○ No one definition
○ Multiple meanings in books and magazines
○ Here, it signifies an always “on”, distributed web, capable of massive scale
PoW to PoS, Casper & Tendermint
● Strategies to arrive at consensus in a distributed network
● Proof of Work expends too much energy.
● PoW is skewed towards those who can spend more money.
● Proof of Stake puts a certain number of coins to give one a chance to mine.
○ More egalitarian. Greater security with more participating nodes.
● Casper: scenarios where little to no assumptions should be made on the
altruism of users or validators, e.g. public blockchains.
● Tendermint: scenarios where participants have existing trust or where chance
of attack is less, e.g. consortium or private/hybrid blockchains
Using Geth Demo & Cmds to use the geth client
Project Links
● Github: https://github.com/ethereum/go-ethereum
● Releases: https://github.com/ethereum/go-ethereum/releases
● Downloads: https://geth.ethereum.org/downloads/
● Main site: https://www.ethereum.org
● Install command line tools: https://www.ethereum.org/cli
Installing Geth
● Bundled as a part of GUI tools like Mist/Ethereum-Wallet
● Installable from source
● Install with package manager
○ Homebrew, apt-get
● From standalone pre-built bundle
From Pre-built Bundle
● My Demo Setup: Google Compute Engine, small VM, Ubuntu, attached and
mounted disk of 100GB
● wget
https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64
-1.5.5-ff07d548.tar.gz
○ Check for latest version at https://geth.ethereum.org/downloads/
● tar -xvf geth-alltools-linux-amd64-1.5.5-ff07d548.tar.gz
● cd geth-alltools-linux-amd64-1.5.5-ff07d548
● ./geth
○ This default command will start an ethereum client node
○ Mining is not automatic/default
● Add geth to PATH if you want
Ethereum Account
● Your unique id on the Ethereum platform
○ A number like 0x2f2c...
● Online services can provide you an ethereum account (like email)
○ myetherwallet.com, coinbase.com, jaxx.io, etc.
● You can also setup your own account
● For convenience, use the GUIs Mist/Ethereum-Wallet
○ Electron based, cross platform Dapp browser/Wallet
● Or use cmd line
● geth account list
○ Account #0: {...key...}
/home/ethmine/.ethereum/keystore/UTC--2016-12-16T19-26-20.479741815Z--[key]
New Ethereum Account with Geth
● geth account new
Your new account is locked with a password. Please give a password. Do
not forget this password.
Passphrase:
Repeat Passphrase:
Address: {2fcb....}
● geth account list
● Any number of accounts can be created.
Backup Keystore and Password
● When you run your own node, backup your keystore and password
○ Imagine if you ran your own email server
● There is no way you can get to your account otherwise
● Locations on OSs
○ Windows: C:Usersusername%appdata%RoamingEthereumkeystore
○ Linux: ~/.ethereum/keystore
○ Mac: ~/Library/Ethereum/keystore
● Backup entire keystore folder …
● Or individual files that look like UTC--2016-12-03T18-26-12.919550734Z--key
Starting a Node
● You will need about 50GB of space as of now
● geth --datadir mydatadir --keystore ~/.ethereum
○ Datadir contains the blockchain data
○ I wanted the datadir to be on a different mount point
● A full sync in the beginning takes quite some time (a few days on a 1v-cpu, 1GB
machine) ...
● Speed it up on first sync by using the --fast option
○ This finished in many minutes
○ Cannot mine with just the fast sync
Exporting and Importing Chaindata
● Export & import existing blockchain data from existing sync-d node
● To export to binary format
○ geth export <filename>
● To import from binary format
○ geth export <filename>
Attaching UI to Node
● When UI starts, it checks for a running node
● If it exists, UI attaches to node
● If not, UI starts a node
○ Default is geth
○ Can configure others
● If you want to have a particular client …
○ Start the ethereum client on cmd line
○ Then start Mist or Ethereum-Wallet UI
1
2
Dir Structure
$ find mydatadir -maxdepth 2
mydatadir
mydatadir/geth
mydatadir/geth/chaindata
mydatadir/geth/nodes
mydatadir/geth/LOCK
mydatadir/geth/nodekey
mydatadir/geth.ipc
$ find ~/.ethereum/ -maxdepth 2
.ethereum/
.ethereum/history
.ethereum/keystore
.ethereum/keystore/UTC--2016-12-16T1
9-26-20.479741815Z--[your key]
Mining
● Run your ethereum node as a miner with --mine option
● To be a miner, you need at least one account, the ‘etherbase’ account
Coinbase/Etherbase Account
● If you mine a block, you get a reward of ETHs
● This is added to your ‘etherbase’ account
○ In bitcoin it is ‘coinbase’. Not to be confused with a company of the same name
● By default it is account ‘0’
○ … as listed in geth account list
● But you can specify another one
● --mine option without etherbase set will error out
geth console
● An interactive javascript console where you can do ‘web3’ programming
● Start with
○ geth console
● Exit with Ctrl+D or with >exit
● Attach to another running geth instance with
○ geth attach
● Then you can use console functions on one terminal while, say, sync logs show
on the other
● If running in a specific dir,
○ geth attach mydatadir/geth.ipc
Console commands
● miner.start()
● miner.stop()
● admin.datadir
● net.peerCount
● admin.peers
● web3.fromWei(eth.getBalance(eth.coinbase), "ether")
● personal.newAccount("password")
● personal.listAccounts
Thank you
Questions
References
● Ethereum fundraiser infogram, with ether supply:
http://i.imgur.com/eI2mffD.png
●
Investing in
Ethereum Can we invest in it like Bitcoin or the
Share Market?
Cryptocurrency Investments
● Extremely volatile in general
● Some gigantic wins; many large losses
● Ether is the token/currency (ETH)
○ <1$ -> ~20$ -> 7.5$
○ Was $1B+ Market cap, but lower now
● Very strong technology
● Very good, responsive, knowledgeable, open team
● Very positive sentiment
● Many new, popular projects on Ethereum platform
● Long term investors using current lows to enter
Price and Market Cap
Ether Supply
● http://ethereum.stackexchange.com/questions/443/what-is-the-total-supply-
of-ether
The issuance model is not fixed yet. It is an ongoing discussion whether
or not the costs for the consensus needs to be financed by inflation that
basically taxes every coin holder or if transaction fees are sufficient.
Please note that the costs for secure consensus are much lower
with Casper compared to current proof of work. More details here
For this reason it is guaranteed, that the current issuance amount
will not be increased and might even drop to 0. Another ongoing
discussion is whether or not issues of new coins should be used to fund
ongoing development. A prerequisites for this would be a DAO with a
widely accepted mechanism to control spending of funds effectively. But
also in this case the newly issued coins would not increase.
60 million + 12 million + 18million = ~90million
60 million - is the Pre-sale.
12 million - is the dev fund, 0.2coins per 1 coin sold in
the crowdsale.
~18 million - 1 million coins mined per month for 18
months prior to going from POW to POS.
inflation
After a while, 15,626,576 ether won't represent much of the
total ether available, making the system dis-inflationary (i.e.,
inflation perpetually trending towards 0 but never reaching it).

gething started - ethereum & using the geth golang client

  • 1.
    gething started geth= golang +blockchain + ethereum sathishvj
  • 2.
    Talk Set: Utilsand Projects in Go ● Identify interesting tools and projects in Go ○ As opposed to focusing only on the language ● Highlight big/awesome projects and inform dev audience it was written in Go ● Encourage open source contribution in Go ● Promote daily use tools written in Go ● SFO searches Go; BLR searches JSP ○ Courtesy: stackoverflow research data ● For orgs shifting to Go, make available a wider developer pool
  • 3.
    Blockchain Intro quick highlightsof blockchain, ethereum
  • 4.
    Blockchain A blockchain isa distributed database that maintains a continuously growing list of records called blocks secured from tampering and revision. Each block contains a timestamp and a link to a previous block. 4See my more elaborate talk at GDG DevFest: slideshare.net/SathishVJ/blockchain-bitcoin
  • 5.
  • 6.
    Bitcoin A distributed, decentralized, digitalcryptocurrency that relies on Blockchain technology. 6
  • 7.
    Ethereum A blockchain-based distributed computingplatform, featuring smart contract functionality. It provides a decentralized virtual machine that can execute peer-to-peer contracts using a cryptocurrency called ether. 7
  • 8.
    Blockchain : Bitcoin: Ethereum Core Tech Gen 1: Special Purpose Apps Next Gen: Platform for Apps 8
  • 9.
  • 10.
    Ethereum Clients ● Multipleclients based on Ethereum Yellow Paper ● In Go, Rust, C++, Python, JavaScript, etc. ● The Go based Ethereum client is called geth ● Got a dedicated website recently ○ Geth.ethereum.org ● Can also be used a library ○ In Mobiles ○ https://ethereum.karalabe.com/talks/2016-devcon.html
  • 11.
    Geth Usage ● Largestethereum client is the go client, geth ● Most versions used are up to date, > 1.5.3
  • 12.
    Miners in India ●About 100 nodes ● Mostly using geth
  • 13.
  • 14.
    Ethereum, Swarm, Whisper ●Contracts: decentralized logic ● Swarm: decentralized storage ● Whisper: decentralized messaging
  • 15.
    Tech Components ● DApp:Distributed Application ● Solidity: a language to write contracts on ethereum ● web3: a library to interact with ethereum blockchain (web3.eth). Contains other objects like (web3.shh for Whisper) ● Import web3.js in your browser to interact with the blockchain ● General term web3 ○ No one definition ○ Multiple meanings in books and magazines ○ Here, it signifies an always “on”, distributed web, capable of massive scale
  • 17.
    PoW to PoS,Casper & Tendermint ● Strategies to arrive at consensus in a distributed network ● Proof of Work expends too much energy. ● PoW is skewed towards those who can spend more money. ● Proof of Stake puts a certain number of coins to give one a chance to mine. ○ More egalitarian. Greater security with more participating nodes. ● Casper: scenarios where little to no assumptions should be made on the altruism of users or validators, e.g. public blockchains. ● Tendermint: scenarios where participants have existing trust or where chance of attack is less, e.g. consortium or private/hybrid blockchains
  • 18.
    Using Geth Demo& Cmds to use the geth client
  • 19.
    Project Links ● Github:https://github.com/ethereum/go-ethereum ● Releases: https://github.com/ethereum/go-ethereum/releases ● Downloads: https://geth.ethereum.org/downloads/ ● Main site: https://www.ethereum.org ● Install command line tools: https://www.ethereum.org/cli
  • 20.
    Installing Geth ● Bundledas a part of GUI tools like Mist/Ethereum-Wallet ● Installable from source ● Install with package manager ○ Homebrew, apt-get ● From standalone pre-built bundle
  • 21.
    From Pre-built Bundle ●My Demo Setup: Google Compute Engine, small VM, Ubuntu, attached and mounted disk of 100GB ● wget https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64 -1.5.5-ff07d548.tar.gz ○ Check for latest version at https://geth.ethereum.org/downloads/ ● tar -xvf geth-alltools-linux-amd64-1.5.5-ff07d548.tar.gz ● cd geth-alltools-linux-amd64-1.5.5-ff07d548 ● ./geth ○ This default command will start an ethereum client node ○ Mining is not automatic/default ● Add geth to PATH if you want
  • 22.
    Ethereum Account ● Yourunique id on the Ethereum platform ○ A number like 0x2f2c... ● Online services can provide you an ethereum account (like email) ○ myetherwallet.com, coinbase.com, jaxx.io, etc. ● You can also setup your own account ● For convenience, use the GUIs Mist/Ethereum-Wallet ○ Electron based, cross platform Dapp browser/Wallet ● Or use cmd line ● geth account list ○ Account #0: {...key...} /home/ethmine/.ethereum/keystore/UTC--2016-12-16T19-26-20.479741815Z--[key]
  • 23.
    New Ethereum Accountwith Geth ● geth account new Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat Passphrase: Address: {2fcb....} ● geth account list ● Any number of accounts can be created.
  • 24.
    Backup Keystore andPassword ● When you run your own node, backup your keystore and password ○ Imagine if you ran your own email server ● There is no way you can get to your account otherwise ● Locations on OSs ○ Windows: C:Usersusername%appdata%RoamingEthereumkeystore ○ Linux: ~/.ethereum/keystore ○ Mac: ~/Library/Ethereum/keystore ● Backup entire keystore folder … ● Or individual files that look like UTC--2016-12-03T18-26-12.919550734Z--key
  • 25.
    Starting a Node ●You will need about 50GB of space as of now ● geth --datadir mydatadir --keystore ~/.ethereum ○ Datadir contains the blockchain data ○ I wanted the datadir to be on a different mount point ● A full sync in the beginning takes quite some time (a few days on a 1v-cpu, 1GB machine) ... ● Speed it up on first sync by using the --fast option ○ This finished in many minutes ○ Cannot mine with just the fast sync
  • 26.
    Exporting and ImportingChaindata ● Export & import existing blockchain data from existing sync-d node ● To export to binary format ○ geth export <filename> ● To import from binary format ○ geth export <filename>
  • 27.
    Attaching UI toNode ● When UI starts, it checks for a running node ● If it exists, UI attaches to node ● If not, UI starts a node ○ Default is geth ○ Can configure others ● If you want to have a particular client … ○ Start the ethereum client on cmd line ○ Then start Mist or Ethereum-Wallet UI 1 2
  • 28.
    Dir Structure $ findmydatadir -maxdepth 2 mydatadir mydatadir/geth mydatadir/geth/chaindata mydatadir/geth/nodes mydatadir/geth/LOCK mydatadir/geth/nodekey mydatadir/geth.ipc $ find ~/.ethereum/ -maxdepth 2 .ethereum/ .ethereum/history .ethereum/keystore .ethereum/keystore/UTC--2016-12-16T1 9-26-20.479741815Z--[your key]
  • 29.
    Mining ● Run yourethereum node as a miner with --mine option ● To be a miner, you need at least one account, the ‘etherbase’ account
  • 30.
    Coinbase/Etherbase Account ● Ifyou mine a block, you get a reward of ETHs ● This is added to your ‘etherbase’ account ○ In bitcoin it is ‘coinbase’. Not to be confused with a company of the same name ● By default it is account ‘0’ ○ … as listed in geth account list ● But you can specify another one ● --mine option without etherbase set will error out
  • 31.
    geth console ● Aninteractive javascript console where you can do ‘web3’ programming ● Start with ○ geth console ● Exit with Ctrl+D or with >exit ● Attach to another running geth instance with ○ geth attach ● Then you can use console functions on one terminal while, say, sync logs show on the other ● If running in a specific dir, ○ geth attach mydatadir/geth.ipc
  • 32.
    Console commands ● miner.start() ●miner.stop() ● admin.datadir ● net.peerCount ● admin.peers ● web3.fromWei(eth.getBalance(eth.coinbase), "ether") ● personal.newAccount("password") ● personal.listAccounts
  • 33.
  • 34.
    References ● Ethereum fundraiserinfogram, with ether supply: http://i.imgur.com/eI2mffD.png ●
  • 35.
    Investing in Ethereum Canwe invest in it like Bitcoin or the Share Market?
  • 36.
    Cryptocurrency Investments ● Extremelyvolatile in general ● Some gigantic wins; many large losses ● Ether is the token/currency (ETH) ○ <1$ -> ~20$ -> 7.5$ ○ Was $1B+ Market cap, but lower now ● Very strong technology ● Very good, responsive, knowledgeable, open team ● Very positive sentiment ● Many new, popular projects on Ethereum platform ● Long term investors using current lows to enter
  • 37.
  • 38.
    Ether Supply ● http://ethereum.stackexchange.com/questions/443/what-is-the-total-supply- of-ether Theissuance model is not fixed yet. It is an ongoing discussion whether or not the costs for the consensus needs to be financed by inflation that basically taxes every coin holder or if transaction fees are sufficient. Please note that the costs for secure consensus are much lower with Casper compared to current proof of work. More details here For this reason it is guaranteed, that the current issuance amount will not be increased and might even drop to 0. Another ongoing discussion is whether or not issues of new coins should be used to fund ongoing development. A prerequisites for this would be a DAO with a widely accepted mechanism to control spending of funds effectively. But also in this case the newly issued coins would not increase. 60 million + 12 million + 18million = ~90million 60 million - is the Pre-sale. 12 million - is the dev fund, 0.2coins per 1 coin sold in the crowdsale. ~18 million - 1 million coins mined per month for 18 months prior to going from POW to POS. inflation After a while, 15,626,576 ether won't represent much of the total ether available, making the system dis-inflationary (i.e., inflation perpetually trending towards 0 but never reaching it).