3

Error

    var error = new Error(message);
                ^

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="retrieve()", data="0x000000000000000000000000000000000000000000000000000000000000007b", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

index.js

const { ethers } = require("ethers");

// const rpcUrl = "https://apothemxdcpayrpc.blocksscan.io/";
// const gorelirpcUrl = "https://eth-goerli.public.blastapi.io";
const infura = "https://goerli.infura.io/v3/";
const provider = new ethers.providers.JsonRpcProvider(infura);
const abi = ["function retrieve() view returns (unit256)"];
const contractAddress = "0xFc1135732B9f32D2785fE5B01a0936074993294A";
const newabi = [
  '[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"save","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
];
const contract = new ethers.Contract(contractAddress, abi, provider);
const main = async () => {
  const num = await contract.retrieve();
  console.log(num);
};

main();

Storage.sol

/**
 *Submitted for verification at Etherscan.io on 2022-05-07
*/

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 * @custom:dev-run-script ./scripts/deploy_with_ethers.ts
 */
contract Storage {

    uint256 number;

    /**
     * @dev Store value in variable
     * @param num value to store
     */
    function store(uint256 num) public {
        number = num;
    }

    /**
     * @dev Return value 
     * @return value of 'number'
     */
    function retrieve() public view returns (uint256){
        return number;
    }
}

It is not working it looks like a error

Thanks in Advance

2 Answers 2

1

You abi does not seem right.

For your contract, I think the abi should be:

[
    {
        "inputs": [],
        "name": "retrieve",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "num",
                "type": "uint256"
            }
        ],
        "name": "store",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    }
]

So, the line:

const abi = ["function retrieve() view returns (unit256)"];

Should be replaced with something like:

const abi = [
    {
        "inputs": [],
        "name": "retrieve",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "num",
                "type": "uint256"
            }
        ],
        "name": "store",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    }
];

Or use your newabi while creating the contract instance.

0

I face this problem and last I found a solution.

In mac and windows, it causes where your project is saved in the documents or Downloads folder or which drive your application has been installed. If you change your drive directory from C:/ to anything else like D:/ or E:/ etc it works fine.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.