【问题标题】:Cannot Connect to local Ethereum node (Mainnet) using Ethers in node.js with Uniswap SDK无法使用带有 Uniswap SDK 的 node.js 中的以太币连接到本地以太坊节点(主网)
【发布时间】:2021-10-29 02:51:02
【问题描述】:

我在本地环境中安装了 Geth,并成功与 ETH 主网同步。我用来启动Geth的命令如下:

geth --ethash.dagdir F:\Ethereum\Ethash --datadir F:\Ethereum --http --graphql --http --http.corsdomain "*" --http.api personal,eth,net,web3

但是,当我尝试使用 ethers 提供程序连接到这个本地以太坊节点时:

let provider = new ethers.providers.JsonRpcProvider();

然后尝试使用此提供程序通过 Uniswap SDK 获取配对信息:

var pair = await uniswap.Fetcher.fetchPairData(tokens.WETH, tokens.DAI, provider);

显示以下错误消息:

(node:32252) UnhandledPromiseRejectionWarning: Error: call revert exception (method="getReserves()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.4.0)  

有人可以帮忙告知这是否与 Geth Ethereum 节点的错误设置有关,还是与使用 uniswap SDK 不正确地使用 ethers 本地 ETH 节点提供程序有关(当我使用 Infura 端点时,上面的工作非常好) ?

【问题讨论】:

    标签: node.js blockchain ethereum geth ethers.js


    【解决方案1】:

    我找到了解决办法!

    事实证明,我的 Geth Ethereum 节点没有完全同步,因此无论我通过 ethers 库进行的任何 API 调用,它都会像 Ethereum 链一样是空的。

    我通过以下方式连接到我的 Geth Ethereum 节点:

    geth attach http://localhost:8545
    

    然后运行命令:

    eth.syncing
    

    检查同步是否完成。如果完成,则返回“false”。

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 2015-11-13
      • 2021-10-17
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多