[블록체인] 이더리움 네트워크 실습

mynameisumin·2023년 11월 27일
post-thumbnail

설치작업

✔︎Geth 설치

  • https://geth.ethereum.org/downloads 접속해서 v1.11.6 설치 (v1.2.0부터는 PoW 지원X)

  • 설치한 파일 압축풀고 Ethereum/PrivateNetwork/node1으로 이동시킴
    $ mv ./Downloads/geth-darwin-amd64-1.11.6-ea9e62ca/geth /yumin/Ethereum/PrivateNetwork/node1

✔︎Go 설치

$ brew install go

테스트-싱글노드

✔︎계정 생성

//node1폴더에 계정생성
$ geth -datadir node1 account new

keystore 파일에 암호화된 형태로 저장됨

✔︎Genesis 블록 초기 설정 (genesis.json)

{
  "config": {
    "chainId": 10,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0
  },
  "coinbase": "0xf078445BEDF74fFe717ea5ff3Cea45c0390f9576",
  "difficulty": "0x20000",
  "extraData": "0x00",
  "gasLimit": "0x2fefd8",
  "nonce": "0x0000000000000042",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "alloc": {
    "0xf078445BEDF74fFe717ea5ff3Cea45c0390f9576": {
      "balance": "400000000000000000000000"
    }
  }
}

✔︎제네시스 블록생성

$ cd
$ cd Ethereum/PrivateNetwork/node1
$ geth --datadir node1 init genesis.json

✔︎노드 실행

$ cd PrivateNetwork/node1
$ geth --datadir node1 --networkid 10 --allow-insecure-unlock --http --http.port 8545 --http.addr "0.0.0.0" --http.corsdomain "*" --http.api "admin,eth,debug,miner,net,txpool,personal,web3" --port 30303 --nodiscover console

✔︎계정 및 잔액 확인

eth.accounts

eth.getBalance(eth.accounts[0])

web3.fromWei(eth.getBalance(eth.accounts[0]))

✔︎블록확인

eth.getBlock(0)

✔︎네트워크확인

net

✔︎geth 대화형 콘솔 시작

$ geth attach rpc:http://localhost:8545

//노드정보확인

admin.nodeInfo
//채굴
miner.setEtherbase(eth.accounts[0])
true
eth.coinbase
"0xf078445bedf74ffe717ea5ff3cea45c0390f9576"
web3.fromWei(eth.getBalance(eth.accounts[0]))
150
eth.blockNumber
30
miner.start()
null


[채굴 시작]

miner.stop()
null
eth.blockNumber
199

//계정 추가 생성 및 계정 확인

personal.newAccount("2345")
"0x5ed1c561677540cb8c50bb372c238e3e5ff6ed92"
eth.accounts
["0xf078445bedf74ffe717ea5ff3cea45c0390f9576", "0x5ed1c561677540cb8c50bb372c238e3e5ff6ed92"]

//송금 트랜잭션 발행

eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(165, "ether")})
잠겨 있어서 잠금을 풀어주어야 함
personal.unlockAccount(eth.accounts[0])
비밀번호 1234 입력
eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(165, "ether")})

//송금 트랜잭션의 정보

eth.getTransaction("0x0cfe645ef72aac570fb2ecb7ef479fa8d0bb9e7c8b70bbe0f6a8863772bbe4ab")

//송금 트랜잭션 완료

eth.pendingTransactions

//계정 잔액 확인

web3.fromWei(eth.getBalance(eth.accounts[0])) //계정1잔액
web3.fromWei(eth.getBalance(eth.accounts[1])) //계정2잔액

테스트-멀티노드

node2디렉토리 생성

✔︎Genesis 블록생성

$ geth --datadir node2 init genesis.json

✔︎노드 실행

$ geth --datadir node2 --allow-insecure-unlock --networkid 10 --http --http.port 8546 --http.addr "0.0.0.0" --http.corsdomain "*" --http.api "admin,eth,debug,miner,net,txpool,personal,web3" --port 30304 --ipcdisable --authrpc.port 8553 --nodiscover console

✔︎노드 간 연결

  • node2에서 node1으로 연결하기 위해서는 node1의 enode 값이 필요

    node1의 enode
    "enode://b274382749989cfd2ece1d41ba3c20cf71faaa5c674610c368b34d3b7370744b47ab439e4a49319bf2189b428a22deab6201ef22f68d6e7e412ed183ade5cf28@127.0.0.1:30303?discport=0"

node2에서

admin.addPeer("enode://b274382749989cfd2ece1d41ba3c20cf71faaa5c674610c368b34d3b7370744b47ab439e4a49319bf2189b428a22deab6201ef22f68d6e7e412ed183ade5cf28@127.0.0.1:30303?discport=0")

노드를 찾지 못하고 있음
✔︎✔︎✔︎✔︎

0개의 댓글