Migration Guide ethers.js v5 to v6
How to migrate your code to ethers.js v6
Last updated
How to migrate your code to ethers.js v6
Last updated
With the @gelatonetwork/relay-sdk
version 5, the package uses ethers.js
v6
. In this guide, we will review the main changes related to the usage of the relay-sdk
.
populateTransaction
methodIn all Relay requests, we send the calldata to be forwarded to the target contract. One way of creating this calldata was by invoking the populateTransaction
method. The way this is done has changed from ethers
v5
to v6
:
ethers@v5
ethers@v6
When instantiating a provider, either on the backend or frontend, you will have to update your code. This is because the package ethers.providers
has been moved to ethers
. So the change would look like this:
ethers@v5
ethers@v6
In addition to the change mentioned above, the Web3Provider
, which was used to instantiate the frontend provider using (window.ethereum)
, is now called BrowserProvider
. So, you'll need to make the following update:
ethers@v5
ethers@v6
When querying the chainId
from the provider in ethers.js
v5
, the result was returned as a number. However, in v6
, the chainId
is returned as a BigInt
. If you have code that relies on the chainId
being a number, you'll need to update it to handle a BigInt
instead.
Here's a simple example that may help you understand how to adapt your code: ethers@v5
ethers@v6
Please visit our , which showcases the usage of the new @gelatonetwork/relay-sdk
v5 implementation for both frontend and backend.