[SOLVED] Reading on chain variables

Hey All,
I’m having a hard time reading on chain variables. Currently I’m using react-moralis and standard moralis, whichever solves the problem first.
I’m trying to read basic public variables on ethereum and for such a simple task im having a hell of a time. My current approach looks like this:

// ABI is in standard format, ADDRESS is a string of the contract address

    await Moralis.Web3API.native
      .runContractFunction({
        address: ADDRESS,
        functionName: "saleIsActive",
        abi: ABI,
      })
      .then((salebool) => {
        console.log(salebool);
        console.log(data);
      });

I’m getting this result:

Am I using the right tool for this or am I way off?

here is an example that works in vanilla js:

I tried it with vanilla JS like this:


     await Moralis.executeFunction({
      contractAddress: ADDRESS,
      functionName: "saleIsActive",
      abi: ABI,
    }).then((res) => {
      console.log(res);
    });

and get this as a response


I know the abi is correct because everything worked fine with web3.js

can you try with the exact example that I posted? (it also include the ABI)

1 Like

Your example worked! thanks so much

For any future troubleshooters, here’s my solution (after adapting it to my situation):

// ABI is in standard format
// ADDRESS is a string of the contract address
// CHAIN_STRING is set to "Rinkeby"

    await Moralis.Web3API.native
      .runContractFunction({
        chain: CHAIN_STRING,
        address: ADDRESS,
        function_name: "saleIsActive",
        abi: ABI,
      })
      .then((response) => {
        console.log(response);
      });