0

I am trying to simply read smart contract data by calling an external view function getOwner which returns an ethereum address using wagmi hook useContractRead. I found that I am getting both the error and data fields non-empty. On further inspection I found that the data that I am getting is correct but theerror is also not empty and the isError is also set to true.

This is the error message string that I am getting

"Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transaction={\"gasLimit\":{\"type\":\"BigNumber\",\"hex\":\"0x01bad458\"},\"to\":\"0xb16DeC9F103B1bf9393380A05363995177C6954C\",\"data\":\"0x893d20e8\",\"accessList\":null}, code=CALL_EXCEPTION, version=providers/5.7.2)\n    at Logger.makeError (webpack-internal:///./node_modules/@ethersproject/logger/lib.esm/index.js:231:23)\n    at Logger.throwError (webpack-internal:///./node_modules/@ethersproject/logger/lib.esm/index.js:240:20)\n    at eval (webpack-internal:///./node_modules/@ethersproject/providers/lib.esm/fallback-provider.js:573:28)\n    at Array.forEach (<anonymous>)\n    at FallbackProvider.eval (webpack-internal:///./node_modules/@ethersproject/providers/lib.esm/fallback-provider.js:553:37)\n    at Generator.next (<anonymous>)\n    at fulfilled (webpack-internal:///./node_modules/@ethersproject/providers/lib.esm/fallback-provider.js:19:58)"

This is the sample code I am using to read data

import ...  // imported necessary packages and modules
...

export default function OwnerDashboard() {
    const router = useRouter()

    const { address: account, isConnected } = useAccount()

    const { chain } = useNetwork()
    const chainId = chain?.id.toString() || "31337"
    console.log(chainId, account)

    const contractReader = useContractRead({
        abi: PatientMedicalRecordSystemAbi,
        address: networkMapping[chainId].PatientMedicalRecordSystem[0],
        functionName: "getOwner",
        onError(error){
            console.log(error)
        }
    })
    console.log(contractReader?.data)
}

The contract function which I am invoking is getOwner from this contract.

Am I using wagmi the wrong way to get the data out? Or what is the issue?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.