i have a function in my smart contract which needs a string to work, and for this i have two options :
OPTION 1 :
Store my string in a state variable :
contract A {
string public immutable myString = "my string in storage"
function myFunction() {
// do something with myString
}
}
OPTION 2 :
Pass as a parameter the string value every time i call the function :
contract A {
function myFunction(string memory _myString) {
// do something with _myString
}
}
My question : What is the most gas efficient option knowing that :
- the string doesn't fit in 32 bytes
- the string value must be immutable