Search code examples
reactjsnode-modulesweb3jsethers.js

How can I use both ethers v5 and v6 node modules in one React project?


In my web3 project, I am using "ethers": '^5.4.7'

but I need to integrate @orionprotocol/sdk node module into my project.

the problem is that this module requires "ethers": '^6.7.0'

enter image description here

I thought that I could do it by upgrading ethers to version 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...
...

However, original code that I wrote in ethers v5 not work anymore.

Of course, I can upgrade all of original codes to new version of ethers, but I think it is not exactly a right solution for me.


Solution

  • You can either:

    1. Alias Ethers 5.4 and use that alias for your code, so you can install both 5.4 and 6.7 at the same time
    2. Upgrade your code to use Ethers 6.7
    3. Use an older version of orionprotocol/sdk which uses an older version of Ethers that will work with your code (e.g. orionprotocol/sdk 19.95 uses version ^5.6.2)