---
# System prepended metadata

title: Geth
tags: [區塊鏈]

---

---
title:  
tags: 區塊鏈
description: 
---

# Geth

## 目錄

## 初始化

> 參考資料： [Installing Geth -> Docker container](https://geth.ethereum.org/docs/getting-started/installing-geth)

```
docker pull ethereum/client-go 將 Docker Image # 拉下來並產生 Container
docker run -it -p 30303:30303 ethereum/client-go # 運行 Container
```

The image has the following ports automatically exposed:

8545 TCP, used by the HTTP based JSON RPC API
8546 TCP, used by the WebSocket based JSON RPC API
8547 TCP, used by the GraphQL API
30303 TCP and UDP, used by the P2P protocol running the network

---

A complete command to start Geth so that it can connect to a consensus client looks as follows:
```
geth --authrpc.addr localhost --authrpc.port 8551 --authrpc.vhosts localhost --authrpc.jwtsecret /tmp/jwtsecret
```

---
There are currently five consensus clients that can be run alongside Geth. These are:

* Lighthouse: written in **Rust**
* Nimbus: written in **Nim**
* Prysm: written in **Go**
* Teku: written in **Java**
* Lodestar: written in **Typescript**

> 我決定使用 Go，因為前面有些環境也是使用 **Go** 的 **Prysm** 了，不增加混亂 [name=孟軒]


## Prysm
1. Create a folder called ethereum on your SSD, and then two subfolders within it: consensus and execution:
    * `mkdir prysm && cd prysm`
    * `curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh && chmod +x prysm.sh `

2. Generate JWT Secret
    * Use Prysm to generate the jwt.hex file:
        * `./prysm.sh beacon-chain generate-auth-secret`
            * 提醒：Windows users may need to run command windows as Administrator.



### 補充：
:::info
* JSON RPC API
    * 此 JSON RPC 接受的語言為 Javascript，也就是說我們可以在 cammand line 的視窗中打上 JS 程式碼來和區塊鏈做互動
    * 我們可使用 JavaScript JSON RPC 與（在）以下開發工具互動：
        * TRUFFLE, Truffle Developer Console
        * TestRPC
        * MIST
        * Remix
        * WEB3.js
* HTTP RESTful Interface
    * geth --rpc 或 Ganache 或 besu --rpc
    * 通常會開啟 RPC Port 於 8545
:::
