Sign Up
Skip to content

Ethers v6 Migration Guide

The @0xsequence package v2.0 now requires at a minimum the Ethers version [email protected].

If you've been developing with ethers@^5.0.0 in the past, outlined below are the common ways using Ethers with Sequence will change for you:

Static and Default RPC Provider

To use ethers to connect and make RPC calls to a blockchain node in order to query information, doing so in a static or default way both have differences:

provider.ts
// v5
const provider = new ethers.providers.StaticJsonRpcProvider(chainConfig.rpcUrl);
 
// v6: If you know the network ahead of time and wish
// to avoid even a single eth_chainId call
const provider = new ethers.JsonRpcProvider(chainConfig.rpcUrl, undefined, {
	staticNetwork: new ethers.Network('<CHAIN_HANDLE>', <CHAIN_ID>)
});
 
// v6: If you want the network automatically detected,
// this will query eth_chainId only once
const provider = new ethers.JsonRpcProvider(chainConfig.rpcUrl, undefined, {
  staticNetwork: true
});

Big Number Support

If you're using big numbers to generate randomly spaced token ID's, nonces, or some other application of large string based numbers, ethers now supports built-in ES2020 BigInt offered by modern JavaScript environments.

bigNumber.ts
// v5
value = BigNumber.from("1000")
 
// v6 
// Notice the suffix n (using literal notation).
value = 1000n
 
// v6 
// Using the BigInt function for strings
value = BigInt("1000")

Removal of Ethers Utilities

Using Ethers you will notice there is no longer a ethers.utils path. Therefore, all paths should be updated without the utils:

contract_parameters.ts
// v5
const amountBigNumber = ethers.utils.parseUnits(String(price), 18); // currency price based on correct decimals for token contract
const erc20Interface = new ethers.utils.Interface([
          "function approve(address spender, uint256 amount) external returns (bool)"
        ]);
        
// v6
const amountBigNumber = ethers.parseUnits(String(price), 18); // currency price based on correct decimals for token contract
const erc20Interface = new ethers.Interface([
          "function approve(address spender, uint256 amount) external returns (bool)"
        ]);

Utility Hash Value Packing

If you're using ethers utilities to perform signature creation then using ecrecover on-chain, signature creation is now slightly different:

signature_creation.ts
// v5
const hash = ethers.utils.solidityKeccak256(['uint', 'uint'], [value1, blockNumber])
const arr = ethers.utils.arrayify(hash)
const signature = await wallet.signMessage(arr)
 
// v6
const hash = ethers.solidityPackedKeccak256(['uint', 'uint'], [value1, blockNumber])
const arr = ethers.getBytes(hash)
const signature = await wallet.signMessage(arr)