Ethers.js vs. Web3.js

I am hoping to migrate to using Ethers.js since it is much more lite weight than Web3.js. However, it appears that Moralis uses Web3. Has the team considered providing another option?

1 Like

You are free to use any web3 provider that you want. We use web3 internally, but you can use ethers.js if you want.
Instead of using const web3 = await Moralis.Web3.enable(), you can setup your web3 provider via ethers.js.

Also note, this article in the ethers.js docs might help you out:

Wow that is great to hear. Just to make sure I understand correctly, so that means the Moralis front-end plugin/library does not come pre-attached with Web3.js, and the web3.js library is only downloaded by the client-side browser if and when const web3 = await Moralis.Web3.enable() is called, right?

Ah, I see what you mean now. If you’re interested in the bundle size, than this won’t work.
Web3 is included in the sdk, as it is used in functions in the sdk. But you still can use ethers.js additionally if you prefer. It will increase the bundle size though, as you include both libraries.

I agree, it would be nice to let users provide the preferred web3 library. Great suggestion. We’ll add it to the feature requests :smiley:


Oh I see. In that case I will stick with using web3.js. Yes, an option to choose the web3 library would be great. Thanks for adding the feature request :slight_smile:

1 Like

I will second that. It would be awesome to use ethers.js directly from the SDK.

1 Like