I am new to solidity and I have been trying to print out simple messages using functions in solidity, but I have failed to deploy successfully, and there is an error that I can not figure out what's wrong.
This is what I have tried so far:
pragma solidity ^0.6.0;
contract test {
string public _feedback;
function reply(string memory feedback) public
{
feedback = "Well done!";
}
}
The error I am receiving is "Warning: Function state mutability can be restricted to pure function"
State mutability is a concept in solidity that defines the behaviour of functions and how they interact with data stored on the blockchain. In this article, you will learn about the different state mutability modifiers and how to apply them in writing optimized smart contracts.
In Solidity, a function that doesn't read or modify the variables of the state is called a pure function. It can only use local variables that are declared in the function and the arguments that are passed to the function to compute or return a value.
View functions are read only function and do not modify the state of the block chain (view data on the block chain). Pure functions do not read and do not modify state of the block chain.
Pure function declares that no state variable will be changed or read.
The compiler simply WARNS that the result of the execution of the function reply is fixed and "canonically" this can be indicated by adding a pure specifier to it:
function reply(string memory feedback) public pure
{
feedback = "Well done!";
}
But even without this change, the contract will be compiled and created correctly. Only in its current form, you will not be able to understand in any way what it is working out :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With