geth를 이용한 private network 구성

스마트컨트랙트

geth를 이용한 배포

remix를 이용한 스마트컨트랙트 배포

통신 과정

Private Network

  1. cmd #1 시작
# C:\Users\SSAFY
mkdir test

# C:\Users\SSAFY\test
mkdir node1 node2

node1: 블록 생성하는 마이너 노드 
node2: 거래 처리하는 서비스 노드
  1. cmd #1: 지갑 생성
# C:\Users\SSAFY\test
geth account new --datadir node1
password 입력, 확인
# 결과
Your new key was generated

Public address of the key:   0xEbEc756269ea9573Fe8b61369F6BBf06D28c5A79
Path of the secret key file: node1\keystore\UTC--2023-09-12T07-02-33.000599500Z--ebec756269ea9573fe8b61369f6bbf06d28c5a79

- You can share your public address with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your funds!
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!

* 0xEbEc756269ea9573Fe8b61369F6BBf06D28c5A79
# C:\Users\SSAFY\test
geth account new --datadir node2
password 입력, 확인
# 결과
Your new key was generated

Public address of the key:   0xB0D7b61E57FEF8C464Ce73056eD4359e15D2C228
Path of the secret key file: node2\keystore\UTC--2023-09-12T07-03-33.378056800Z--b0d7b61e57fef8c464ce73056ed4359e15d2c228

- You can share your public address with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your funds!
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!

* 0xB0D7b61E57FEF8C464Ce73056eD4359e15D2C228
  1. test 폴더: 제네시스 블록(최초 블록) 생성
# C:\Users\SSAFY\test
genesis.json 파일 생성

{
  "config": {
    "chainId": 12345,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "clique": {
      "period": 5,
      "epoch": 30000
    }
  },
  "difficulty": "1",
  "gasLimit": "8000000",
  "extradata": "0x0000000000000000000000000000000000000000000000000000000000000000EbEc756269ea9573Fe8b61369F6BBf06D28c5A790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "alloc": {
    "EbEc756269ea9573Fe8b61369F6BBf06D28c5A79": { "balance": "500000000000000000000" },
    "B0D7b61E57FEF8C464Ce73056eD4359e15D2C228": { "balance": "500000000000000000000" }
  }
}

- period : 블록 간의 간격을 초 단위로 정의. 이 경우 5초
- epoch: 블록을 그룹화하는 단위인 에포크의 크기를 정의
- chainId : 이더리움 네트워크 서버 id
- gasLimit : 해당 노드에서 최대로 처리할수 있는 gas, gas는 연료의 개념으로 이더 전송의 기본 가스 소묘량은 21000, 스마트컨트랙트는 실행된코드에 따라 달라지게된다.
- difficulty : nonce와 마찬가지로 POW 알고리즘 동작에 사용되는 파라미터, 알고리즘에 의해 값 변경 블록 생성주기가 10~20초 사이가 되도록 설정
- alloc : 초기에 state를 정의하는 부분, 즉, 이더리움을 틀정 지갑에 할당하거나 스마트 컨트랙트를 배포하는 용도

- coinbase : 마이닝 시 보상받을 지갑주소, prefix로 0x 붙이기
- nonce : POW 알고리즘에 사용하는 파라미터 초기설정
- timestatmp : 첫 번째 블록이 만들어진 시간, 16진수로 변환된 값을 넣어준다.
- parantHash : 이전블록 해쉬값, 첫 노드는 없기 때문에 0x0으로 작성
  1. cmd #1: 제네시스 블록을 사용하는 블록체인 노드를 생성