0

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?

Null isTrue
  • 1,882
  • 6
  • 26
  • 46

1 Answers1

1

I would like to go point-by-point to your question :

  1. 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.

  2. Is that the correct practice? Kind-of, Yes

  3. Is there a better approach to this? The method can be modified to view restriction

  4. 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.

  5. 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!

Manik Jain
  • 86
  • 4
  • thank you so much really appreciate it - so on 4. I could also make it a constant i.e. `string constant myValue = "foo"` (?) - Also I read the docs regarding the strings and couldn't find a way to write multiple lines without getting a compile error. I'm using remix. Back-ticks are not allowed as a syntax and I'd like to avoid adding `/n` for every line break I may need. Do you mind posting an example on how to do so? – Null isTrue Apr 30 '21 at 19:22
  • There are actually 2 approaches how you can achieve it : 1. \n : which you don't want to use 2. string memory toReturn = "Some random string goes here " "and here as well"; More can be read from. : https://docs.soliditylang.org/en/v0.8.0/types.html?highlight=multiline%20string#string-literals-and-types – Manik Jain Apr 30 '21 at 19:43