Criando um nó privado Ethereum

         Bom pessoal o objetivo deste post é mostrar como criar um nó privado do blockchain da ethereum e dar um overview sobre como interagimos com este nó, este ambiente que montaremos é próprio para desenvolvimento e explorar esta tecnologia de blockchain, bom sem muitas delongas vamos  entradar no site  https://geth.ethereum.org/downloads/ nele podemos conseguir os pacotes para os principais sistemas operacionais da atualidade

O que é o Geth ?, O Geth o software disponibilizado para poder ter um nó do blockchain da fundação ethereum, baixado o pacote para seu sistema operacional vamos para instalação

geth1

  1. Instalando no windows, a instalação no windows segue o padrão next, next, finish

geth2

geth3

geth4

geth5

2. Instalação no Linux

a primeira ação a ser tomada e baixar o a versao do geth para linux, será um arquivo compactado um .tar.gz, para esta versão sara algo semelhante á “geth-linux-amd64-1.8.2-b8b9f7f4.tar.gz” apos descompactado teremos algo parecido com

/home/george/Downloads/geth-linux-amd64-1.8.2-b8b9f7f4

para finalizar so falta configurar o PATH com o Geth, para isso podemos usar o seguinte comando

~$ echo ‘export PATH=$PATH:/home/george/Downloads/geth-linux-amd64-1.8.2-b8b9f7f4/’ >> ~/.bashrc

3. Explorando o nó

uma das primeiras coisas a se fazer é saber se temos a variável de sistema do geth no path do sistema e conseguimos isso com o comando

geth version, e se tudo estiver corretamente instalado teremos esta saida

Geth
Version: 1.8.2-stable
Git Commit: b8b9f7f4476a30a0aaf6077daade6ae77f969960
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.2
Operating System: windows
GOPATH=
GOROOT=c:\go

agora se quisermos mas informações sobre os paramentros que o comando geth no proporciona, podemos ter esta informação da seguinte forma

geth help


NAME:
   geth - the go-ethereum command line interface

   Copyright 2013-2017 The go-ethereum Authors

USAGE:
   geth [options] command [command options] [arguments...]

VERSION:
   1.8.2-stable-b8b9f7f4

COMMANDS:
   account     Manage accounts
   attach      Start an interactive JavaScript environment (connect to node)
   bug         opens a window to report a bug on the geth repo
   console     Start an interactive JavaScript environment
   copydb      Create a local chain from a target chaindata folder
   dump        Dump a specific block from storage
   dumpconfig  Show configuration values
   export      Export blockchain into file
   import      Import a blockchain file
   init        Bootstrap and initialize a new genesis block
   js          Execute the specified JavaScript files
   license     Display license information
   makecache   Generate ethash verification cache (for testing)
   makedag     Generate ethash mining DAG (for testing)
   monitor     Monitor and visualize node metrics
   removedb    Remove blockchain and state databases
   version     Print version numbers
   wallet      Manage Ethereum presale wallets
   help, h     Shows a list of commands or help for one command

ETHEREUM OPTIONS:
  --config value                                        TOML configuration file
  --datadir "C:\Users\george\AppData\Roaming\Ethereum"  Data directory for the databases and keystore
  --keystore                                            Directory for the keystore (default = inside the datadir)
  --nousb                                               Disables monitoring for and managing USB hardware wallets
  --networkid value                                     Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1)
  --testnet                                             Ropsten network: pre-configured proof-of-work test network
  --rinkeby                                             Rinkeby network: pre-configured proof-of-authority test network
  --syncmode "fast"                                     Blockchain sync mode ("fast", "full", or "light")
  --gcmode value                                        Blockchain garbage collection mode ("full", "archive") (default: "full")
  --ethstats value                                      Reporting URL of a ethstats service (nodename:secret@host:port)
  --identity value                                      Custom node name
  --lightserv value                                     Maximum percentage of time allowed for serving LES requests (0-90) (default: 0)
  --lightpeers value                                    Maximum number of LES client peers (default: 100)
  --lightkdf                                            Reduce key-derivation RAM & CPU usage at some expense of KDF strength

DEVELOPER CHAIN OPTIONS:
  --dev               Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled
  --dev.period value  Block period to use in developer mode (0 = mine only if transaction pending) (default: 0)

ETHASH OPTIONS:
  --ethash.cachedir                                 Directory to store the ethash verification caches (default = inside the datadir)
  --ethash.cachesinmem value                        Number of recent ethash caches to keep in memory (16MB each) (default: 2)
  --ethash.cachesondisk value                       Number of recent ethash caches to keep on disk (16MB each) (default: 3)
  --ethash.dagdir "C:\Users\george\AppData\Ethash"  Directory to store the ethash mining DAGs (default = inside home folder)
  --ethash.dagsinmem value                          Number of recent ethash mining DAGs to keep in memory (1+GB each) (default: 1)
  --ethash.dagsondisk value                         Number of recent ethash mining DAGs to keep on disk (1+GB each) (default: 2)

TRANSACTION POOL OPTIONS:
  --txpool.nolocals            Disables price exemptions for locally submitted transactions
  --txpool.journal value       Disk journal for local transaction to survive node restarts (default: "transactions.rlp")
  --txpool.rejournal value     Time interval to regenerate the local transaction journal (default: 1h0m0s)
  --txpool.pricelimit value    Minimum gas price limit to enforce for acceptance into the pool (default: 1)
  --txpool.pricebump value     Price bump percentage to replace an already existing transaction (default: 10)
  --txpool.accountslots value  Minimum number of executable transaction slots guaranteed per account (default: 16)
  --txpool.globalslots value   Maximum number of executable transaction slots for all accounts (default: 4096)
  --txpool.accountqueue value  Maximum number of non-executable transaction slots permitted per account (default: 64)
  --txpool.globalqueue value   Maximum number of non-executable transaction slots for all accounts (default: 1024)
  --txpool.lifetime value      Maximum amount of time non-executable transaction are queued (default: 3h0m0s)

PERFORMANCE TUNING OPTIONS:
  --cache value            Megabytes of memory allocated to internal caching (default: 1024)
  --cache.database value   Percentage of cache memory allowance to use for database io (default: 75)
  --cache.gc value         Percentage of cache memory allowance to use for trie pruning (default: 25)
  --trie-cache-gens value  Number of trie node generations to keep in memory (default: 120)

ACCOUNT OPTIONS:
  --unlock value    Comma separated list of accounts to unlock
  --password value  Password file to use for non-interactive password input

API AND CONSOLE OPTIONS:
  --rpc                  Enable the HTTP-RPC server
  --rpcaddr value        HTTP-RPC server listening interface (default: "localhost")
  --rpcport value        HTTP-RPC server listening port (default: 8545)
  --rpcapi value         API's offered over the HTTP-RPC interface
  --ws                   Enable the WS-RPC server
  --wsaddr value         WS-RPC server listening interface (default: "localhost")
  --wsport value         WS-RPC server listening port (default: 8546)
  --wsapi value          API's offered over the WS-RPC interface
  --wsorigins value      Origins from which to accept websockets requests
  --ipcdisable           Disable the IPC-RPC server
  --ipcpath              Filename for IPC socket/pipe within the datadir (explicit paths escape it)
  --rpccorsdomain value  Comma separated list of domains from which to accept cross origin requests (browser enforced)
  --rpcvhosts value      Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
  --jspath loadScript    JavaScript root path for loadScript (default: ".")
  --exec value           Execute JavaScript statement
  --preload value        Comma separated list of JavaScript files to preload into the console

NETWORKING OPTIONS:
  --bootnodes value     Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers)
  --bootnodesv4 value   Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes)
  --bootnodesv5 value   Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes)
  --port value          Network listening port (default: 30303)
  --maxpeers value      Maximum number of network peers (network disabled if set to 0) (default: 25)
  --maxpendpeers value  Maximum number of pending connection attempts (defaults used if set to 0) (default: 0)
  --nat value           NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: "any")
  --nodiscover          Disables the peer discovery mechanism (manual peer addition)
  --v5disc              Enables the experimental RLPx V5 (Topic Discovery) mechanism
  --netrestrict value   Restricts network communication to the given IP networks (CIDR masks)
  --nodekey value       P2P node key file
  --nodekeyhex value    P2P node key as hex (for testing)

MINER OPTIONS:
  --mine                    Enable mining
  --minerthreads value      Number of CPU threads to use for mining (default: 4)
  --etherbase value         Public address for block mining rewards (default = first account created) (default: "0")
  --targetgaslimit value    Target gas limit sets the artificial target gas floor for the blocks to mine (default: 4712388)
  --gasprice "18000000000"  Minimal gas price to accept for mining a transactions
  --extradata value         Block extra data set by the miner (default = client version)

GAS PRICE ORACLE OPTIONS:
  --gpoblocks value      Number of recent blocks to check for gas prices (default: 20)
  --gpopercentile value  Suggested gas price is the given percentile of a set of recent transaction gas prices (default: 60)

VIRTUAL MACHINE OPTIONS:
  --vmdebug  Record information useful for VM and contract debugging

LOGGING AND DEBUGGING OPTIONS:
  --metrics                 Enable metrics collection and reporting
  --fakepow                 Disables proof-of-work verification
  --nocompaction            Disables db compaction after import
  --verbosity value         Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)
  --vmodule value           Per-module verbosity: comma-separated list of = (e.g. eth/*=5,p2p=4)
  --backtrace value         Request a stack trace at a specific logging statement (e.g. "block.go:271")
  --debug                   Prepends log messages with call-site location (file and line number)
  --pprof                   Enable the pprof HTTP server
  --pprofaddr value         pprof HTTP server listening interface (default: "127.0.0.1")
  --pprofport value         pprof HTTP server listening port (default: 6060)
  --memprofilerate value    Turn on memory profiling with the given rate (default: 524288)
  --blockprofilerate value  Turn on block profiling with the given rate (default: 0)
  --cpuprofile value        Write CPU profile to the given file
  --trace value             Write execution trace to the given file

WHISPER (EXPERIMENTAL) OPTIONS:
  --shh                       Enable Whisper
  --shh.maxmessagesize value  Max message size accepted (default: 1048576)
  --shh.pow value             Minimum POW accepted (default: 0.2)

DEPRECATED OPTIONS:
  --fast   Enable fast syncing through state downloads
  --light  Enable light client mode

MISC OPTIONS:
  --help, -h  show help

COPYRIGHT:
   Copyright 2013-2017 The go-ethereum Authors

agora vamos subir nosso nó local
geth –dev –datadir private –rpc –rpcapi ‘admin,personal,eth,web3,debug,net’ –rpcaddr localhost –rpcport 8545

significado dos parâmetros:
–dev : sobe o nó em modo de desenvolvimento
–datadir private : passa uma pasta “private” para armazenar as dados gerados pelo nó
–rpc : habilita protocolo de comunicação rpc
–rpcapi: habilita pai de comunicação com o nó
–rpcaddr localhost: indica um endereço para nó
–rpcport 8545: indica a porta de comunicação
‘admin,personal,eth,web3,debug,net’: são as API que serão disponibilizadas

INFO [03-10|22:05:10] Maximum peer count                       ETH=25 LES=0 total=25
INFO [03-10|22:05:11] Using developer account                  address=0x5790Db5C836BD21a3E2292F7E24E1243995f0338
INFO [03-10|22:05:11] Starting peer-to-peer node               instance=Geth/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2
INFO [03-10|22:05:11] Allocated cache and file handles         database=C:\\Users\\george\\private\\aulaonline\\geth\\chaindata cache=768 handles=1024

INFO [03-10|22:05:11] Persisted trie from memory database      nodes=11 size=2.17kB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-10|22:05:11] Initialised chain configuration          config="{ChainID: 1337 Homestead: 0 DAO:  DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople:  Engine: clique}"
INFO [03-10|22:05:11] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [03-10|22:05:11] Loaded most recent local header          number=7 hash=5b7238…e64b62 td=15
INFO [03-10|22:05:11] Loaded most recent local full block      number=7 hash=5b7238…e64b62 td=15
INFO [03-10|22:05:11] Loaded most recent local fast block      number=7 hash=5b7238…e64b62 td=15
INFO [03-10|22:05:11] Loaded local transaction journal         transactions=0 dropped=0
INFO [03-10|22:05:11] Regenerated local transaction journal    transactions=0 accounts=0
WARN [03-10|22:05:11] Blockchain not empty, fast sync disabled
INFO [03-10|22:05:11] Starting P2P networking
INFO [03-10|22:05:11] RLPx listener up                         self="enode://2c80d90c9e438f27cb660bc36ae8d5ee1c3cbba315063af9824769e58647b186b676d6f86944ee29e925976150adb42640f874222c1a9ee89427fcbc74c62080@[::]:54063?discport=0"
INFO [03-10|22:05:11] started whisper v.5.0
INFO [03-10|22:05:11] IPC endpoint opened                      url=\\\\.\\pipe\\geth.ipc
INFO [03-10|22:05:11] HTTP endpoint opened                     url=http://127.0.0.1:8545 cors= vhosts=localhost
INFO [03-10|22:05:11] Transaction pool price threshold updated price=18000000000
INFO [03-10|22:05:11] Etherbase automatically configured       address=0x5790Db5C836BD21a3E2292F7E24E1243995f0338
INFO [03-10|22:05:11] Starting mining operation
INFO [03-10|22:05:11] Commit new mining work                   number=8 txs=0 uncles=0 elapsed=0s
WARN [03-10|22:05:11] Block sealing failed                     err="waiting for transactions"
INFO [03-10|22:05:14] Mapped network port                      proto=tcp extport=54063 intport=54063 interface="UPNP IGDv1-IP1"

um outro comando interessante é o geth –dev console

INFO [03-10|22:06:07] Maximum peer count                       ETH=25 LES=0 total=25
INFO [03-10|22:06:09] Using developer account                  address=0x23F8727df78bc8d6f5966A9624BBf1aC8b918802
INFO [03-10|22:06:09] Starting peer-to-peer node               instance=Geth/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2
INFO [03-10|22:06:09] Writing custom genesis block
INFO [03-10|22:06:09] Persisted trie from memory database      nodes=13 size=2.32kB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-10|22:06:09] Initialised chain configuration          config="{ChainID: 1337 Homestead: 0 DAO:  DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople:  Engine: clique}"
INFO [03-10|22:06:09] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [03-10|22:06:09] Loaded most recent local header          number=0 hash=77e873…8a5b6c td=1
INFO [03-10|22:06:09] Loaded most recent local full block      number=0 hash=77e873…8a5b6c td=1
INFO [03-10|22:06:09] Loaded most recent local fast block      number=0 hash=77e873…8a5b6c td=1
INFO [03-10|22:06:09] Starting P2P networking
INFO [03-10|22:06:09] RLPx listener up                         self="enode://2c53a7bd55c684b3f7151c41fc5771785bb45d87339d0f733cac3aa8792e1579d66fd46caf5a8431abab0f98a7bffd7f4f4caa82af8e267426eeaac70fe0faac@[::]:54072?discport=0"
INFO [03-10|22:06:09] started whisper v.5.0
INFO [03-10|22:06:09] IPC endpoint opened                      url=\\\\.\\pipe\\geth.ipc
INFO [03-10|22:06:09] Transaction pool price threshold updated price=18000000000
INFO [03-10|22:06:09] Etherbase automatically configured       address=0x23F8727df78bc8d6f5966A9624BBf1aC8b918802
INFO [03-10|22:06:09] Starting mining operation
INFO [03-10|22:06:09] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=0s
WARN [03-10|22:06:09] Block sealing failed                     err="waiting for transactions"
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2
coinbase: 0x23f8727df78bc8d6f5966a9624bbf1ac8b918802
at block: 0 (Wed, 31 Dec 1969 22:00:00 -02)
 datadir:
 modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0

> INFO [03-10|22:06:12] Mapped network port                      proto=tcp extport=54072 intport=54072 interface="UPNP IGDv1-IP1"

este comando abre um console javascript para interagirmos com geth, depois de executado escte comando podemons vamos obtter informações sobre os modulos
admin e eth so para mostrar o seu funcionamento, com o Geth JavaScript console aberto digitamos admin e em seguida eth e teremos as seguintes saidas
respectivamentes

admin

{
  datadir: "",
  nodeInfo: {
    enode: "enode://18924129ec9253b4483edcf30ffc69a66ff25e67bdce74465ed9c2b93978bbace5cef95eadfed9d483f34c76025e31b9817b225712db78ce97b51c26b216cbbd@[::]:54626?discport=0",
    id: "18924129ec9253b4483edcf30ffc69a66ff25e67bdce74465ed9c2b93978bbace5cef95eadfed9d483f34c76025e31b9817b225712db78ce97b51c26b216cbbd",
    ip: "::",
    listenAddr: "[::]:54626",
    name: "Geth/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2",
    ports: {
      discovery: 0,
      listener: 54626
    },
    protocols: {
      eth: {
        config: {...},
        difficulty: 1,
        genesis: "0xad8b4e51887fdfc438945c012f01e0e944fe0265f3718f059d1b32ee931edc63",
        head: "0xad8b4e51887fdfc438945c012f01e0e944fe0265f3718f059d1b32ee931edc63",
        network: 1
      },
      shh: {
        maxMessageSize: 1048576,
        minimumPoW: 0.2,
        version: "5.0"
      }
    }
  },
  peers: [],
  addPeer: function(),
  clearHistory: function(),
  exportChain: function(),
  getDatadir: function(callback),
  getNodeInfo: function(callback),
  getPeers: function(callback),
  importChain: function(),
  removePeer: function(),
  sleep: function github.com/ethereum/go-ethereum/console.(*bridge).Sleep-fm(),
  sleepBlocks: function github.com/ethereum/go-ethereum/console.(*bridge).SleepBlocks-fm(),
  startRPC: function(),
  startWS: function(),
  stopRPC: function(),
  stopWS: function()
}

eth

{
  accounts: ["0x8e08c5576bedee610858facb999af84510a1505d"],
  blockNumber: 0,
  coinbase: "0x8e08c5576bedee610858facb999af84510a1505d",
  compile: {
    lll: function(),
    serpent: function(),
    solidity: function()
  },
  defaultAccount: undefined,
  defaultBlock: "latest",
  gasPrice: 1,
  hashrate: 0,
  mining: true,
  pendingTransactions: [],
  protocolVersion: "0x3f",
  syncing: false,
  call: function(),
  contract: function(abi),
  estimateGas: function(),
  filter: function(options, callback, filterCreationErrorCallback),
  getAccounts: function(callback),
  getBalance: function(),
  getBlock: function(),
  getBlockNumber: function(callback),
  getBlockTransactionCount: function(),
  getBlockUncleCount: function(),
  getCode: function(),
  getCoinbase: function(callback),
  getCompilers: function(),
  getGasPrice: function(callback),
  getHashrate: function(callback),
  getMining: function(callback),
  getPendingTransactions: function(callback),
  getProtocolVersion: function(callback),
  getRawTransaction: function(),
  getRawTransactionFromBlock: function(),
  getStorageAt: function(),
  getSyncing: function(callback),
  getTransaction: function(),
  getTransactionCount: function(),
  getTransactionFromBlock: function(),
  getTransactionReceipt: function(),
  getUncle: function(),
  getWork: function(),
  iban: function(iban),
  icapNamereg: function(),
  isSyncing: function(callback),
  namereg: function(),
  resend: function(),
  sendIBANTransaction: function(),
  sendRawTransaction: function(),
  sendTransaction: function(),
  sign: function(),
  signTransaction: function(),
  submitTransaction: function(),
  submitWork: function()
}
Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

w

Conectando a %s

Blog no WordPress.com.

Acima ↑

%d blogueiros gostam disto: