TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

Consider using ethers sub-packages to reduce bundle sizes

Open smartcontracts opened this issue 3 years ago • 3 comments

Hi! Optimism is in the process of trying to reduce bundle sizes for down-stream users of our contract packages. TypeChain currently imports ethers in its entirety into typing files but could instead import specific sub-packages. For example, contract type files import the following:

import type { Listener } from "@ethersproject/providers";
import type { Event, EventFilter } from "ethers";

This can be replaced with

import type { Listener } from "@ethersproject/providers";
import type { Event, EventFilter } from "@ethersproject/contracts";

smartcontracts avatar Sep 14 '22 17:09 smartcontracts

+1, I've run into issues with bundle size and conflicting ethers packages. This would at least prevent the number of packages that need to be cross-installed.

iainnash avatar Sep 19 '22 10:09 iainnash

+1 this would be a nice improvement to remove "ethers" dependency

asooge avatar Sep 26 '22 18:09 asooge

Few things that may help with reducing bundle sizes further:

  • Each bytecode can be around 10kb to 24kb. If there are a lot of them, it can add up. Currently, if contract instances are created through ERC20__factory.connect(address, provider), it also touches the bytecode hence bundler has to include it. This might need a simple ERC20__contract which only touches abi.
  • We can explore using human-readable ABI since it's more compact than minified JSON fragments.

zemse avatar Oct 01 '22 15:10 zemse