'How do I return anything from a function after changing a state variable in solidity?
function setName(string memory _name) public returns(string memory){
name = _name;
return "Name was set";
}
I want to return a confirmation message after the string was set but whenever I try to deploy, its working fine and even the name is being set but it's not returning the string "Name was set". Can anyone help me out with this? Thank you!
Solution 1:[1]
State changing functions don't exactly return something you can use in the common sense outside your smart contract, such as in testing.
For that purpose, we use Events to log what happened, and then query the logs or simply call the getter function after you are done executing your setter function.
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 |
