ethers의 Contract에 JsonRPCprovider를 먹이면 혼나요.
2792 단어 TypeScriptEthereumetherstech
컨디션
재현 코드
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]
로 업데이트되었습니다.
Reference
이 문제에 관하여(ethers의 Contract에 JsonRPCprovider를 먹이면 혼나요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/serinuntius/articles/54b2666904877d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)