簡體   English   中英

如何正確設置 geth 以進行 JSON RPC 調用

[英]How do I properly set up geth to make JSON RPC calls

我安裝了 Geth 以觸發對以太坊測試網 Goerli 的 JSON RPC 調用。 我按照這里的入門教程進行操作。 我按照說明進行了以下操作:

  1. 通過調用clef newaccount --keystore <my_local_dir>/keystore生成了一個新賬戶(錢包地址)
  2. 在 Goerli 上啟動 clef(鏈 ID 為 5)並通過指向密鑰庫目錄來使用新生成的密鑰clef --keystore <my_local_dir>/keystore --configdir <my_local_dir>/clef --chainid 5
  3. 通過調用geth --datadir <my_local_dir> --signer=<my_local_dir>/clef/clef.ipc --goerli --syncmode snap --http開始 geth 與節點同步
  4. 通過調用geth attach http://127.0.0.1:8545附加到正在運行的節點。 雖然,我相信這一步可以跳過,因為我試圖觸發 JSON RPC 請求
  5. 通過 postman 發出請求 - 生成的 curl 命令如下:
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x631e9b031b16b18172a2b9d66c3668a68a668d20", "latest"],
    "id": 1
}'

我可能做錯了什么? 我看到該帳戶確實有以太幣( 余額),但由於我的調用,我一直得到 0:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0x0"
}

任何想法?

經過一些額外的研究並與同事交談后,我相信我現在知道為什么我無法檢索區塊鏈數據了。 僅在節點完全同步后才可用:

Client execution will initiate its core functions, chosen endpoints, and start looking for peers. After successfully discovering peers, the client starts synchronization. Current blockchain data will be available once the client is successfully synced to the current state.

這可以在此處的最后一段中找到。

所以問題不是安裝或設置失敗,而是客戶端不同步。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM