Reputation: 1906
Where in the code and what is the proper way to add legal verbiage to my ERC20 Smart Contract?
I've seen a few samples where it gets saved on a variable and then that variable value is referenced in the body of a function using memory
.
i.e.
contract MyToken is ERC20, Ownable {
string public processNumber = "0041518-41.1982.8.26.0053";
string public legalBinding = "a lot, a lot of verbiage would go here";
constructor() ERC20("MyToken", "MTK") {
_mint(msg.sender, 9000000 * 10 ** decimals());
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function setProcessNumber (string memory v) public onlyOwner() {
processNumber = v;
}
function setLegalBinding (string memory v) public onlyOwner() {
legalBinding = v;
}
}
What are those two last functions doing anyway does it ever get executed or just saved in memory?
Is that the correct practice?
Is there a better approach to this?
Where in the code do developers typically add that type of info?
If I'm to save a massive string of text containing all the legal verbiage. on a variable can I save those on a template literal using back-ticks to leverage multiple lines breaks inside the string and so forth?
Upvotes: 0
Views: 56
Reputation: 86
I would like to go point-by-point to your question :
What are those two last functions doing anyway does it ever get executed or just saved in memory?
These functions are basically overriding the values of these variables, which in your case, are by default initialised at the very beginning of the contract. As we have the onlyOwner() modifier set on these functions, only the owner can change these variables by calling these methods explicitly, and by providing the necessary Gas cost.
Is that the correct practice? Kind-of, Yes
Is there a better approach to this? The method can be modified to view restriction
Where in the code do developers typically add that type of info? If you want the value to be a constant, i.e, it should not be changed through out the course of the contract, add the constant modifier. Additionally, you can add make the variable immutable, which means the initial constant value string can be avoided, and the variable can only be initialised with a constant value at first run, and then the value cannot be changed.
If I'm to save a massive string of text containing all the legal verbiage. on a variable can I save those on a template literal using back-ticks to leverage multiple lines breaks inside the string and so forth? Yes, you can. Please refer here : https://docs.soliditylang.org/en/v0.8.0/internals/layout_in_storage.html?highlight=string
Hope that it helps!
Upvotes: 1