The array of bytes is basically a string. The variable called name has a type of array of bytes or string. Its visibility is public. If you want to set it to private, then just omit the public keyword, as follows:
If you are coming from a Python background, then you will recognize the Python decorator function. There are four of these in Vyper:
@public means you can execute this method as a user (just as you did in the Truffle console in the previous chapter).
@privatemeans that only other methods inside the same smart contract can access this method. You cannot call the method as a user (in the Truffle console).
@payablemeans that you can send some ethers to this method.
@constis an indicator that this method should not modify the state of a smart contract. It means that it will not cost ether to execute this method. It’s like reading a public variable's value.
Going back to the __init__() method, you could pass a parameter to this method like this:
Don't forget to send the parameter when you deploy a smart contract. In our case, we use migration in Truffle software, so modify your migration file, 2_deploy_hello.js, to be as follows:
You must be careful with the return value of the method indicated by the right arrow (→). You might set this to an array of bytes that does not have enough length. For example, take a look at the following code:
In this case, it would fail in compilation, although "Hello, Satoshi Nakamoto" is definitely less than 28 characters. The string has a length of 23 characters; however, you must remember that self.name is defined as bytes[24], and Hello, has a length of 7 characters. Because 24 + 7 is 31 characters, you must set this to a bigger array.
Since this method does not change the state of this smart contract, you can add @const on top of this method, as follows: