Web3js

使用奇偶校驗作為從 Docker 容器執行的 Web3 提供程序

  • September 27, 2018

我似乎無法創建一個指向奇偶校驗節點的 web3 (http) 提供程序,從 docker 容器執行。我創建了一個應該重現問題的儲存庫。

執行docker-compose up奇偶校驗後啟動,但應用程序失敗:

Creating network "dockerweb3_net" with driver "bridge"
Attaching to qa_parity, qa_app
qa_parity | 2018-09-27 07:50:52 UTC Starting Parity-Ethereum/v2.0.6-stable-7658d22-20180921/x86_64-linux-gnu/rustc1.29.0
qa_parity | 2018-09-27 07:50:52 UTC Keys path /root/.local/share/io.parity.ethereum//keys/test
qa_parity | 2018-09-27 07:50:52 UTC DB path /root/.local/share/io.parity.ethereum//chains/test/db/ae90623718e47d66
qa_parity | 2018-09-27 07:50:52 UTC State DB configuration: fast
qa_parity | 2018-09-27 07:50:52 UTC Operating mode: active
qa_parity | 2018-09-27 07:50:52 UTC Configured for Ropsten using Ethash engine

qa_app    | /app/app.js:6
qa_app    |   throw "Can't connect to Ethereum node: qa_parity:8545";

現在,如果我在同一個 docker 網路上獲得失敗容器的外殼,我可以達到奇偶校驗:

docker run --net dockerweb3_net -it dockerweb3_app /bin/bash

curl --data '{"method":"web3_clientVersion","params":[],"id":1,"jsonrpc":"2.0"}' \
-H "Content-Type: application/json" \
-X POST qa_parity:8545

> {"jsonrpc":"2.0","result":"Parity-Ethereum//v2.0.6-stable-7658d22-20180921/x86_64-linux-gnu/rustc1.29.0","id":1}

由於暴露了8545,奇偶校驗也可以從主機(http://localhost:8545)到達,所以問題一定出在創建提供者的時候。

似乎 web3 只需要完整路徑而不僅僅是 IP 地址。連接到容器並傳遞 url 工作:

env URL_PARITY="http://qa_parity:8545" node app.js

引用自:https://ethereum.stackexchange.com/questions/59547