Preloader image
DDD

블럭체인

Ethereum - Geth 사용 가이드

작성자 관리자 (admin)
조회수 13,267
입력일 2018-12-13 10:52:35

Ethereum - Geth

    : 이더리움 다운로드 : https://geth.ethereum.org/downloads/
    : install C:\Geth
    : genesis.json 파일 생성 ( 아래와 같이 - C:\Geth\genesis.json )

{
    "nonce": "0x0000000000000042",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "difficulty": "0x400",
    "alloc": {},
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x",
    "gasLimit": "0xffffffff",
    "config": {
        "chainId": 33273743010,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
        }
}
    

    : Geth Console 로 들어가기
    : C:\Geth\geth –datadir C:\Geth init C:\Geth\genesis.json

    INFO [12-12|13:48:11.904] Maximum peer count                       ETH=25 LES=0 total=25
    INFO [12-12|13:48:11.956] Allocated cache and file handles         database=C:\\Geth\\geth\\chaindata cache=16 handles=16
    INFO [12-12|13:48:11.982] Writing custom genesis block
    INFO [12-12|13:48:11.986] Persisted trie from memory database      nodes=0 size=0.00B time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
    INFO [12-12|13:48:11.997] Successfully wrote genesis state         database=chaindata                 hash=272003…b62890
    INFO [12-12|13:48:12.005] Allocated cache and file handles         database=C:\\Geth\\geth\\lightchaindata cache=16 handles=16
    INFO [12-12|13:48:12.032] Writing custom genesis block
    INFO [12-12|13:48:12.036] Persisted trie from memory database      nodes=0 size=0.00B time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
    INFO [12-12|13:48:12.045] Successfully wrote genesis state         database=lightchaindata                 hash=272003…b62890

    > C:\Geth\geth  –networkid 1185 –nodiscover –maxpeers 0 –datadir C:\Geth console 2>> C:\Geth\geth.log
    Welcome to the Geth JavaScript console!
    
    instance: Geth/v1.8.20-stable-24d727b6/windows-amd64/go1.11.2
     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
    
    >
    > eth.coinbase
    X  etherbase must be explicitly specified
    > personal.newAccount()
    Passphrase: **your_password**
    Repeat passphrase: **your_password**
    "0xe25192575c3f0e8dd719450a260185fb1cbcd48f"
    > eth.coinbase
    "0xe25192575c3f0e8dd719450a260185fb1cbcd48f"
    > eth.getBalance(eth.accounts[0])
    0
    > miner.start(1)
    null
    > eth.mining
    true
    > eth.hashrate
    0
    > eth.blockNumber
    0
    > miner.stop()
    null
    > eth.hashrate
    27167
    > eth.blockNumber
    57
    > eth.getBalance(eth.accounts[0])
    285000000000000000000
    > web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
    285
    > eth.blockNumber
    57
    : 현재 채굴로 받을 수 있는 보상은 1블록에 5ether이다.
    : 채굴을 중단할 때까지 블록의 길이가 178이었으므로 57×5=285 다.

    ::::::::::::::::::::::::
    :: 송금을 위한 다른 계정 생성 ::
    ::::::::::::::::::::::::

    > personal.newAccount()
    Passphrase: **your_password**
    Repeat passphrase: **your_password**
    "0x25f79f8ea74251eaf57731299b114a775bad77ec"
    > eth.hashrate
    0
    > eth.blockNumber
    57
    > eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10,"ether")})
    Error: authentication needed: password or unlock
        at web3.js:3143:20
        at web3.js:6347:15
        at web3.js:5081:36
        at :1:1

    > personal.unlockAccount(eth.accounts[0],"**your_password**")
    true
    > eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10,"ether")})
    "0x841de180be09a7212ab242d29d4913605f8fabaecda39c5f37a522c02ff20e17"
    > eth.hashrate
    0
    : 아직 진행 중이므로 송금이 되지 않은 것을 확인 할 수 있다.

    > eth.pendingTransactions
    [{
        blockHash: null,
        blockNumber: null,
        from: "0xe25192575c3f0e8dd719450a260185fb1cbcd48f",
        gas: 90000,
        gasPrice: 1000000000,
        hash: "0x841de180be09a7212ab242d29d4913605f8fabaecda39c5f37a522c02ff20e17",
        input: "0x",
        nonce: 0,
        r: "0xcaba9c6af363cba73e98811b1dc3c630ae9ef80f969ce17ea0a4fe7735cdbf35",
        s: "0x793c821a27058ab50f291340a477204c3c8e0b5318fe5777444b1942549dd283",
        to: "0x25f79f8ea74251eaf57731299b114a775bad77ec",
        transactionIndex: 0,
        v: "0xf7e8a0d68",
        value: 10000000000000000000
    }]
    > miner.start(1)
    null
    > eth.pendingTransactions
    []
    >
    
    > eth.getBalance(eth.accounts[1])
    10000000000000000000
    > eth.getBalance(eth.accounts[2])
    Error: invalid address
        at web3.js:3930:15
        at web3.js:5025:28
        at map ()
        at web3.js:5024:12
        at web3.js:5050:18
        at web3.js:5075:23
        at :1:1
    
    > eth.getBalance(eth.accounts[0])
    635000000000000000000

    > eth.getTransaction("0x841de180be09a7212ab242d29d4913605f8fabaecda39c5f37a522c02ff20e17")
    {
      blockHash: "0xeedae1ba0141b88e3a2250898787cbad4d2890ef783ec8800e6a099db92a8bfb",
      blockNumber: 58,
      from: "0xe25192575c3f0e8dd719450a260185fb1cbcd48f",
      gas: 90000,
      gasPrice: 1000000000,
      hash: "0x841de180be09a7212ab242d29d4913605f8fabaecda39c5f37a522c02ff20e17",
      input: "0x",
      nonce: 0,
      r: "0xcaba9c6af363cba73e98811b1dc3c630ae9ef80f969ce17ea0a4fe7735cdbf35",
      s: "0x793c821a27058ab50f291340a477204c3c8e0b5318fe5777444b1942549dd283",
      to: "0x25f79f8ea74251eaf57731299b114a775bad77ec",
      transactionIndex: 0,
      v: "0xf7e8a0d68",
      value: 10000000000000000000
    }
    > exit