I am having a bit of trouble using web3.eth.Contract with Typescript..
import * as ERC721ABI from "../ABIs/ERC721.json";
import Web3 from "web3";
...
const contract = new web3.eth.Contract(ERC721ABI, event.target.value);
...
The error I am receiving is:
Argument of type '({ inputs: { internalType: string; name: string; type: string; }[]; stateMutability: string; type: string; anonymous?: undefined; name?: undefined; outputs?: undefined; } | { anonymous: boolean; inputs: { ...; }[]; name: string; type: string; stateMutability?: undefined; outputs?: undefined; } | { ...; })[]' is not assignable to parameter of type 'AbiItem | AbiItem[]'.
Type '({ inputs: { internalType: string; name: string; type: string; }[]; stateMutability: string; type: string; anonymous?: undefined; name?: undefined; outputs?: undefined; } | { anonymous: boolean; inputs: { ...; }[]; name: string; type: string; stateMutability?: undefined; outputs?: undefined; } | { ...; })[]' is not assignable to type 'AbiItem[]'.
Type '{ inputs: { internalType: string; name: string; type: string; }[]; stateMutability: string; type: string; anonymous?: undefined; name?: undefined; outputs?: undefined; } | { anonymous: boolean; inputs: { ...; }[]; name: string; type: string; stateMutability?: undefined; outputs?: undefined; } | { ...; }' is not assignable to type 'AbiItem'.
Type '{ inputs: { internalType: string; name: string; type: string; }[]; stateMutability: string; type: string; anonymous?: undefined; name?: undefined; outputs?: undefined; }' is not assignable to type 'AbiItem'.
Types of property 'stateMutability' are incompatible.
Type 'string' is not assignable to type '"nonpayable" | "view" | "pure" | "payable" | undefined'. TS2345
90 |
91 | try {
> 92 | const contract = new web3.eth.Contract(ERC721ABI, event.target.value);
Any idea what I'm doing wrong here?
Also, is it possible to import multiple ABIs into web3.eth.Contract, or would I have to create separate instances for each ABI?
Finally, any idea which ABI I would need to use for interacting with Wallets, or would that need a separate call? I'm not quite sure whether Wallets on Ethereum are ALSO smart contracts, or just a public key.
Thanks
Best Answer
you can also do