'ethers can't get pure function return value
I built a test solidity pure function to display a greeting message.
It only returns a string "Hello User".
Here is the contract code:
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract Greeter {
function SayHi() public pure returns(string memory){
return "Hello User";
}
}
and here is the function in react. I'm calling the solidity function. (Note: all required connection to wallet and to contract is done)
const getMsg = async () => {
try {
if (!ethereum) return alert("Please install MetaMask.");
console.log('Fetching MEssage...')
let msg = await Contract.SayHi();
console.log('Message:', msg)
// setmessage(msg);
} catch (error) {
console.log(error);
throw new Error("No ethereum object");
}
};
after this I get nothing in the log statement. I didn't get the return value.
So how can I access it?
Solution 1:[1]
Issue is Solved by deploying the contract on the same Network that i am connected to by:
npx hardhat run --network ropsten .\scripts\deploy.js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dev. Mahmoud |