ethers-multicall icon indicating copy to clipboard operation
ethers-multicall copied to clipboard

Strongly-typed contracts

Open janklimo opened this issue 3 years ago • 3 comments

Is there a way to currently (or in the future) make the contract aware of the functions it supports? Example:

Screen Shot 2021-05-09 at 01 36 19

Thanks to TypeChain we have a generated contract type which would be as follows for the example above:

start_time(
  overrides?: CallOverrides
): Promise<{
  0: BigNumber;
}>;

I'm thinking there might be a way to pass it to the Contract class if we make it generic — taking contract type as a type argument.

janklimo avatar May 08 '21 18:05 janklimo

It would be great to see it natively supported by the package.

Till then, we can do like this:

const contract = new MulticallContract(address, ABI) as unknown as ContractType

apoorvlathey avatar Nov 01 '21 09:11 apoorvlathey

It would be great to see it natively supported by the package.

Till then, we can do like this:

const contract = new MulticallContract(address, ABI) as unknown as ContractType

Will return values with typed in this expression when calling provider.all?

ChrisChan888 avatar Feb 07 '22 03:02 ChrisChan888

It would be great to see it natively supported by the package. Till then, we can do like this:

const contract = new MulticallContract(address, ABI) as unknown as ContractType

Will return values with typed in this expression when calling provider.all?

image

Sadly no. You'd have to provide the return datatypes manually to .all as shown above

apoorvlathey avatar Feb 10 '22 20:02 apoorvlathey