Skip to main content
added 1942 characters in body; edited tags
Source Link
contract Twitter {
    //Struct for user profile
    struct Profile {
        string name;
        string username;
        string bio;
        string location;
        string profilePic;
    }

//Struct for tweets
    struct Tweet {
        uint256 _id;
        string tweetImg;
        string tweetText;
        uint256 timeStamp;
        string profileImg;
        string name;
        string username;
        uint256 likes;
    }

    mapping(address => Profile) public profiles;
    mapping(address => Tweet[]) public tweets;
    Tweet[] public allTweets;
    uint256 public tweetCounter;

    function createProfile(
        string memory _name,
        string memory _username,
        string memory _bio,
        string memory _location,
        string memory _profilePic,
        string memory _coverPic
    ) public {
        require(
            bytes(profiles[msg.sender].username).length == 0,
            "User already exists."
        );
        Profile memory newProfile = Profile(
            _name,
            _username,
            _bio,
            _location,
            _profilePic,
            _coverPic
        );
        profiles[msg.sender] = newProfile;
    }

    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;
        }
    }
}
  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");
    }
  }

const onSubmit = async (data) => {
    try {
      if (disabled) return;
      const { coverPic, profilePic, name, username, location, bio } = data;
      const provider = new ethers.BrowserProvider(window.ethereum);
      const signer = provider.getSigner();
      const contract = new ethers.Contract(
        CONTRACT_ADDRESS,
        CONTRACT_ABI,
        signer
        );
      const response = await contract.createProfile(
        name,
        username,
        bio,
        location,
        profilePic,
        coverPic
      );
      await response.wait();
      console.log(response, "response");
    } catch (error) {
      console.error(error, "ERROR");
    }
  };

When I run the code, I'm getting thisThe "checkProfileIsExist" function works since it's a get function. BUt the "onSubmit" function is not working. It throws the error,

app-index.js:31 Error: couldcontract runner does not decode result data (value="0x",support sending transactions info={ "method": "checkProfile", "signature": "checkProfile(address)" }operation="sendTransaction", code=BAD_DATAcode=UNSUPPORTED_OPERATION, version=6 version=6.8.0)

The account addressThis is sending correctlymy hardhat.config file,

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.19",
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${API_KEY}`,
      accounts: [
        `${PRIVATE_KEY}`,
      ],
    },
  },
};

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. No documentation is clear about it. Any help on this would be appreciated since I'm new to blockchain dev.

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;
        }
    }
}
  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.

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

//Struct for tweets
    struct Tweet {
        uint256 _id;
        string tweetImg;
        string tweetText;
        uint256 timeStamp;
        string profileImg;
        string name;
        string username;
        uint256 likes;
    }

    mapping(address => Profile) public profiles;
    mapping(address => Tweet[]) public tweets;
    Tweet[] public allTweets;
    uint256 public tweetCounter;

    function createProfile(
        string memory _name,
        string memory _username,
        string memory _bio,
        string memory _location,
        string memory _profilePic,
        string memory _coverPic
    ) public {
        require(
            bytes(profiles[msg.sender].username).length == 0,
            "User already exists."
        );
        Profile memory newProfile = Profile(
            _name,
            _username,
            _bio,
            _location,
            _profilePic,
            _coverPic
        );
        profiles[msg.sender] = newProfile;
    }

    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;
        }
    }
}
  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");
    }
  }

const onSubmit = async (data) => {
    try {
      if (disabled) return;
      const { coverPic, profilePic, name, username, location, bio } = data;
      const provider = new ethers.BrowserProvider(window.ethereum);
      const signer = provider.getSigner();
      const contract = new ethers.Contract(
        CONTRACT_ADDRESS,
        CONTRACT_ABI,
        signer
        );
      const response = await contract.createProfile(
        name,
        username,
        bio,
        location,
        profilePic,
        coverPic
      );
      await response.wait();
      console.log(response, "response");
    } catch (error) {
      console.error(error, "ERROR");
    }
  };

When I run the code, The "checkProfileIsExist" function works since it's a get function. BUt the "onSubmit" function is not working. It throws the error,

contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.8.0)

This is my hardhat.config file,

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.19",
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${API_KEY}`,
      accounts: [
        `${PRIVATE_KEY}`,
      ],
    },
  },
};

I don't know why this error comes. No documentation is clear about it. Any help on this would be appreciated since I'm new to blockchain dev.

added 42 characters in body
Source Link

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 ahshas 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.

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)

I don't know why this error is coming. the abi ahs 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.

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.

Source Link

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)

I don't know why this error is coming. the abi ahs 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.