Smart Contracts – Resolving Type ‘Number’ Not Assignable to Type ‘BigNumber’ Error in ABI

ethers.jsreactwagmi

This is the first time I work with web3 api, so I am totally lost.
I use wagmi hook with react, trying to call a function from smart contract:

const id = 1;
const index = 1;

 const { data, error, isError, isLoading } = useContractRead({
    address: "0xADDRESS",
    abi: [(...){
        inputs: [
          { internalType: "uint256", name: "id", type: "uint256" },
          { internalType: "uint256", name: "index", type: "uint256" },
        ],
        name: "isClaimed",
        outputs: [{ internalType: "bool", name: "", type: "bool" }],
        stateMutability: "view",
        type: "function",
      },(...)],
    functionName: "isClaimed",
    args: [id, index],
  });

and I get the IDE error: "Type 'number' is not assignable to type 'BigNumber'"

if I then

const id = BigNumber.from(1);

then I get error from the contract:

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="isClaimed(uint256,uint256)", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0) at Logger.makeError (index.ts:269:1) at Logger.throwError (index.ts:281:1) at Interface.decodeFunctionResult (interface.ts:427:1) at index.ts:400:1 at Generator.next () at fulfilled (index.ts:1:1)

I watched several tutorials and read articles about it but still have no idea what is the problem. Wagmi documentation doesn't tell me anything about it. ChatGPT nor Bing Chat are not helpful. Can anyone help?

———— Edit: Additional Info —————-

I have this in my App.txs:

const chains = [arbitrum, mainnet, polygon];
const projectId = "SOME_ID_OF_WALLETCONNECT_PROJECT_I_CREATED";

const { provider } = configureChains(chains, [w3mProvider({ projectId })]);
const wagmiClient = createClient({
  autoConnect: true,
  connectors: w3mConnectors({ projectId, version: 1, chains }),
  provider,
});

Contract developer said that chain is Mumbai testing for polygon. I guess I am not connected to the correct chain then

Best Answer

The Error you pasted seems a bit unrelated to the description. The error shows that you are calling method isClaimed(uint256,uint256) with data=0x. Perhaps you are making a call somewhere to that method without providing input arguments?

It is difficult to say without seeing the rest of the code.

----------------------------- EDIT --------------------------------

The exception provides you this link: https://links.ethers.org/v5-errors-CALL_EXCEPTION

This type of exception happens if you try to access a method that doesn't exist for a specific address. A very common case is that you try to access "the right method and the right address" but in the wrong network. Make sure you are only trying to call that contract method in the chain where it is deployed.

Related Topic