如何在一个 React 项目中同时使用 ethers v5 和 v6 节点模块?

问题描述 投票:0回答:1

在我的 web3 项目中,我使用 "ethers": '^5.4.7'

但是我需要将 @orionprotocol/sdk 节点模块集成到我的项目中。

问题是这个模块需要 "ethers": '^6.7.0'

我以为我可以通过将以太币升级到版本6来做到这一点....

const tokenFrom = from === ethers.constants.AddressZero ? nativeToken : from;
const tokenTo = to === ethers.constants.AddressZero ? nativeToken : to;

// above code does not work in ethers v6, because there is no scope named "ethers.constants" and so on...
...

但是,我在 ethers v5 中编写的原始代码不再起作用。

当然,我可以将所有原始代码升级到新版本的以太坊,但我认为这对我来说并不是一个正确的解决方案。

reactjs node-modules web3js ethers.js
1个回答
0
投票

您可以:

  1. 别名 Ethers 5.7 并为您的代码使用该别名,这样您就可以同时安装 5.7 和 6.7
  2. 升级您的代码以使用 Ethers 6.7
  3. 使用旧版本的 orionprotocol/sdk,它使用旧版本的 Ethers,可与您的代码配合使用(例如 orionprotocol/sdk 19.95 使用版本 ^5.6.2
© www.soinside.com 2019 - 2024. All rights reserved.