dethcrypto / TypeChain

🔌 TypeScript bindings for Ethereum smart contracts
MIT License
2.73k stars 353 forks source link

I want to use strict type to get contract response #889

Closed ilya-korotya closed 6 months ago

ilya-korotya commented 6 months ago

Currently, typechain plugin for hardhat generates code like:

getUserCredential(
    _userId: BigNumberish,
    overrides?: CallOverrides
  ): Promise<
    ([
      BigNumber,
      [string, string, string],
      [string, string],
      BigNumber,
      BigNumber,
      BigNumber,
      ... & {
      id: BigNumber;
      context: [string, string, string];
      types: [string, string];
      expirationDate: BigNumber;
      issuanceDate: BigNumber;
      issuer: BigNumber;
      credentialSubject: ([string, BigNumber, string] & {
        key: string;
        value: BigNumber;
        rawValue: string;
      })[];
      credentialStatus: [string, string, BigNumber] & {
        id: string;
        _type: string;
        revNonce: BigNumber;
      };

What is the reason for returning an untyped array? When I use JSON.stringify on the result of the getUserCredential function, I receive an array instead of an object. How can I obtain only an object as the result of the getUserCredential function?

krzkaczor commented 6 months ago

@ilya-korotya most likely what you get from TypeChain is an array with additional properties attached (& {...} part). This is unfortunately how ethers.js was designed.

You can simply ignore the fact that it's an array and focus on object fields.