Ethereum docker geth web3 test 私有网络

ready

  • docker
  • node

Ethereum docker geth

1、vim genesis.json

{
  "config": {                                                                         
    "chainId": 110,                                                                   
    "homesteadBlock": 0,                                                              
    "eip150Block": 0,                                                                 
    "eip155Block": 0,                                                                 
    "eip158Block": 0,                                                                 
    "byzantiumBlock": 0,                                                              
    "constantinopleBlock": 0,                                                         
    "petersburgBlock": 0,                                                             
    "istanbulBlock": 0                                                                
  },                                                                                  
	"alloc": {                                                                                                                                                    
		"0x0000000000000000000000000000000000000001": {                                     
		"balance": "111111111"                                 
		},                      
		"0x0000000000000000000000000000000000000002": {
		"balance": "222222222"                                                        
		}                                                                                                                                   
	},                                                                           
  "coinbase": "0x0000000000000000000000000000000000000000",
  "difficulty": "0x20000",                                                        
  "extraData": "",                                                                   
  "gasLimit": "0x2fefd8",       
  "nonce": "0x0000000000000042",                                                  
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",   
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00"
}

2、docker run -d --name ethereum-node -v /home/eth/ethereum:/root -p 8545:8545 -p 30303:30303 ethereum/client-go
docker exec -it ethereum-node /bin/sh

[root@localhost eth]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
ethereum/client-go           latest              9c42a1a55bef        21 hours ago        44.6MB

3、geth --datadir data0 init genesis.json

~ # geth --datadir data0 init genesis.json
INFO [04-08|06:24:31.570] Maximum peer count ETH=50 LES=0 total=50
INFO [04-08|06:24:31.570] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [04-08|06:24:31.572] Allocated cache and file handles         database=/root/data0/geth/chaindata cache=16.00MiB handles=16
INFO [04-08|06:24:31.609] Persisted trie from memory database      nodes=3 size=399.00B time=39.6µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-08|06:24:31.610] Successfully wrote genesis state         database=chaindata                  hash=a3c5c1…d6926b
INFO [04-08|06:24:31.610] Allocated cache and file handles         database=/root/data0/geth/lightchaindata cache=16.00MiB handles=16
INFO [04-08|06:24:31.641] Persisted trie from memory database      nodes=3 size=399.00B time=19.8µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-08|06:24:31.641] Successfully wrote genesis state         database=lightchaindata                  hash=a3c5c1…d6926b

4、geth --identity “testEth” --rpc --rpcaddr 0.0.0.0 --datadir data0 --port “3033” --nodiscover console

geth --identity "testEth" --rpc --rpcaddr 0.0.0.0 --rpcport "8545" --datadir data0 --port "3033" --nodiscover console

INFO [04-08|06:25:57.686] Starting Geth on Ethereum mainnet... 
INFO [04-08|06:25:57.686] Bumping default cache on mainnet         provided=1024 updated=4096
WARN [04-08|06:25:57.687] Sanitizing cache to Go's GC limits       provided=4096 updated=308
INFO [04-08|06:25:57.689] Maximum peer count                       ETH=50 LES=0 total=50
INFO [04-08|06:25:57.689] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [04-08|06:25:57.693] Starting peer-to-peer node               instance=Geth/testEth/v1.9.13-unstable-15540ae9-20200409/linux-amd64/go1.13.9
INFO [04-08|06:25:57.693] Allocated trie memory caches             clean=46.00MiB dirty=77.00MiB
INFO [04-08|06:25:57.693] Allocated cache and file handles         database=/root/data0/geth/chaindata cache=154.00MiB handles=524288
INFO [04-08|06:25:57.741] Opened ancient database                  database=/root/data0/geth/chaindata/ancient
INFO [04-08|06:25:57.741] Initialised chain configuration          config="{ChainID: 110 Homestead: 0 DAO:  DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: , Engine: unknown}"
INFO [04-08|06:25:57.742] Disk storage enabled for ethash caches   dir=/root/data0/geth/ethash count=3
INFO [04-08|06:25:57.742] Disk storage enabled for ethash DAGs     dir=/root/.ethash           count=2
INFO [04-08|06:25:57.742] Initialising Ethereum protocol           versions="[65 64 63]" network=1 dbversion=7
INFO [04-08|06:25:57.743] Loaded most recent local header          number=0 hash=a3c5c1…d6926b td=131072 age=51y2d6h
INFO [04-08|06:25:57.743] Loaded most recent local full block      number=0 hash=a3c5c1…d6926b td=131072 age=51y2d6h
INFO [04-08|06:25:57.743] Loaded most recent local fast block      number=0 hash=a3c5c1…d6926b td=131072 age=51y2d6h
INFO [04-08|06:25:57.743] Loaded local transaction journal         transactions=0 dropped=0
INFO [04-08|06:25:57.743] Regenerated local transaction journal    transactions=0 accounts=0
INFO [04-08|06:25:57.747] Allocated fast sync bloom                size=123.00MiB
INFO [04-08|06:25:57.749] Initialized fast sync bloom              items=3 errorrate=0.000 elapsed=143.7µs
INFO [04-08|06:25:57.780] IPC endpoint opened                      url=/root/data0/geth.ipc
INFO [04-08|06:25:57.780] HTTP endpoint opened                     url=http://[::]:8545/    cors= vhosts=localhost
INFO [04-08|06:25:57.804] New local node record                    seq=3 id=43f175918c86c1fb ip=127.0.0.1 udp=0 tcp=3033
INFO [04-08|06:25:57.804] Started P2P networking                   self="enode://23158cb4369db9de6304c00866831abfe6a84c83465fd237677c9b16d1e8dfd4bb877b971739405f858402abe8bfeeb337f479049d2ec92fe08b3884be2979bc@127.0.0.1:3033?discport=0"
INFO [04-08|06:25:57.881] Etherbase automatically configured       address=0xc474A4203176797aF41AdA1e0483D74A4D0E3De6
Welcome to the Geth JavaScript console!

instance: Geth/testEth/v1.9.13-unstable-15540ae9-20200409/linux-amd64/go1.13.9
coinbase: 0xc474a4203176797af41ada1e0483d74a4d0e3de6
at block: 0 (Thu Jan 01 1970 00:00:00 GMT+0000 (UTC))
 datadir: /root/data0
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

5、eth

> eth
{
  accounts: ["0xc474a4203176797af41ada1e0483d74a4d0e3de6"],
  blockNumber: 0,
  coinbase: "0xc474a4203176797af41ada1e0483d74a4d0e3de6",
  compile: {
    lll: function(),
    serpent: function(),
    solidity: function()
  },
  defaultAccount: undefined,
  defaultBlock: "latest",
  gasPrice: 1000000000,
  hashrate: 0,
  mining: false,
  pendingTransactions: [],
  protocolVersion: "0x41",
  syncing: false,
  call: function(),
  chainId: function(),
  contract: function(abi),
  estimateGas: function(),
  fillTransaction: function(),
  filter: function(options, callback, filterCreationErrorCallback),
  getAccounts: function(callback),
  getBalance: function(),
  getBlock: function(),
  getBlockByHash: function(),
  getBlockByNumber: function(),
  getBlockNumber: function(callback),
  getBlockTransactionCount: function(),
  getBlockUncleCount: function(),
  getCode: function(),
  getCoinbase: function(callback),
  getCompilers: function(),
  getGasPrice: function(callback),
  getHashrate: function(callback),
  getHeaderByHash: function(),
  getHeaderByNumber: function(),
  getMining: function(callback),
  getPendingTransactions: function(callback),
  getProof: function(),
  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()
}

6、eth.accounts

> eth.accounts
["0xc474a4203176797af41ada1e0483d74a4d0e3de6"]

web3

1、install node
2、install web3

cnpm install web3.js --save

3、web3 txWeb3.js

var Web3 = require('web3')
var web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.11.11:8545"));
console.log(web3.version)
console.log(web3.eth.getBlock(0))

4、run
node txWeb3.js

F:\web3>node 1.js
{
  api: '0.20.7',
  node: [Getter],
  getNode: [Function: get] { request: [Function: bound ] },
  network: [Getter],
  getNetwork: [Function: get] { request: [Function: bound ] },
  ethereum: [Getter],
  getEthereum: [Function: get] { request: [Function: bound ] },
  whisper: [Getter],
  getWhisper: [Function: get] { request: [Function: bound ] }
}
{
  difficulty: BigNumber { s: 1, e: 5, c: [ 131072 ] },
  extraData: '0x',
  gasLimit: 3141592,
  gasUsed: 0,
  hash: '0xa3c5c170988f516e00ea3078b2461a149bcd4d0422c8c894923c6cfa22d6926b',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  miner: '0x0000000000000000000000000000000000000000',
  mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
  nonce: '0x0000000000000042',
  number: 0,
  parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
  receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
  sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
  size: 507,
  stateRoot: '0x92683e6af0f8a932e5fe08c870f2ae9d287e39d4518ec544b0be451f1035fd39',
  timestamp: 0,
  totalDifficulty: BigNumber { s: 1, e: 5, c: [ 131072 ] },
  transactions: [],
  transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
  uncles: []
}

你可能感兴趣的:(ethereum,区块链)