Skip to content

Error: call revert exception CALL_EXCEPTION  #1804

@ghost

Description

Describe the bug
I am getting an revert exception in my React app even the created instance exists. At const exchange = await this.getExchange(exchangeAddress); the error occurs. For a while it had worked and then it didn't anymore. I could not reproduce the error. Testing with Hardhat against local network.

  import Exchange from '../abi/src/contracts/Exchange.sol/Exchange.json';
                ....
                ....
               .....
  getExchange = async (exchangeAddress: string) => {
    const exchange = new ethers.Contract(
      exchangeAddress,
      Exchange.abi,
      this.state.signer
    );
    return exchange;
  };

Is consumed in:

  getTokenAmount = async (ethAmount: string) => {
    try {
      const exchangeAddress =
        await this.state.factory.callStatic.createExchange(
          REACT_APP_TOKEN_ADDRESS,
          {
            from: this.state.account,
          }
        );

      const exchange = await this.getExchange(exchangeAddress); 
      console.log(exchange) // <-- the exchange instance exists in the browser console
      const res = await exchange.getTokenAmount(ethAmount);// <- throws revert exception

      return res;
    } catch (err) {
      console.log(err);
    }
  };

Reproduction steps
ABI for Exchange contract:
https://github.com/melonecrypto/meloneswap/tree/main/src/abi/src/contracts/Exchange.sol

Error in Browser

Error: call revert exception (method="getTokenAmount(uint256)", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.4.0)
    at Logger.makeError (index.ts:213)
    at Logger.throwError (index.ts:225)
    at Interface.decodeFunctionResult (interface.ts:425)
    at Contract.<anonymous> (index.ts:332)
    at Generator.next (<anonymous>)
    at fulfilled (index.ts:2)

Environment:
OS: MAC OS Big Sur
Editor: VS-Code
Testing-Environment: Hardhat : 2.5.0 localhost: url: 'http://127.0.0.1:8545'
Package.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionQuestions, feedback and general information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions