ethers의 Contract에 JsonRPCprovider를 먹이면 혼나요.

컨디션

  • [email protected]
  • @ethersproject/[email protected]
  • [email protected]
  • 재현 코드


    import { Contract } from 'ethers';
    import { JsonRpcProvider } from '@ethersproject/providers';
    const abi = [];
    const provider = new JsonRpcProvider('');
    const contract = new Contract('', abi, provider);
    // Argument of type 'JsonRpcProvider' is not assignable to parameter of type 'Provider | Signer | undefined'.
    // Type 'JsonRpcProvider' is not assignable to type 'Provider'.
    //    The types returned by 'resolveName(...)' are incompatible between these types.
    //     Type 'Promise<string | null>' is not assignable to type 'Promise<string>'.
    //     Type 'string | null' is not assignable to type 'string'.
    //     Type 'null' is not assignable to type 'string'.ts(2345)
    

    까닭


    일반적으로 ethers의 버전이 일치하지 않는다고 생각합니다.
    에스린트@ethersproject/providers는 import이지만 dependencies에 추가되지 않았기 때문에 잡지에 넣으면providers만 최신 버전이고 원래의 ethers는 조금 오래된 버전을 사용해서 만들어진 것이라고 한다.

    해결책


    버전 일치를 위해 [email protected]로 업데이트되었습니다.

    좋은 웹페이지 즐겨찾기