Skip to main content
2 of 3
added 42 characters in body

Calling smart contract function from frontend is not working

I've created a twitter profile contract and a function called

contract Twitter {
    //Struct for user profile
    struct Profile {
        string name;
        string username;
        string bio;
        string location;
        string profilePic;
    }

    mapping(address => Profile) public profiles;

    //Check profile exists
    function checkProfile(address _address) public view returns (bool) {
        if (bytes(profiles[_address].username).length > 0) {
            return true;
        } else {
            return false;
        }
    }
}

And I've generated the contract address and abi by deploying the code using hardhat.

Then called the function form the frontend like this

  const checkProfileIsExist = async () => {
    try {
      const provider = new ethers.BrowserProvider(window.ethereum);
      const signer = await provider.getSigner();
      const contract = new ethers.Contract(
        CONTRACT_ADDRESS,
        CONTRACT_ABI,
        signer
      );
      const response = await contract.checkProfile(account);
      console.log(response, "res");
    } catch (error) {
      console.error(error, "ERROR");
    }
  }

When I run the code, I'm getting this error

app-index.js:31 Error: could not decode result data (value="0x", info={ "method": "checkProfile", "signature": "checkProfile(address)" }, code=BAD_DATA, version=6.8.0)

The account address is sending correctly. I don't know why this error is coming. the abi has the "checkProfile" entity as well. When I tried the same using remix IDE with it's address and abi, I'm getting the result correctly. But this error comes when I use hardhat address and abi by deploying it. Any help on this would be appreciated since I'm new to blockchain dev.