Functions
A function in Vyper is exactly like a function in a Python program. You group statements inside a code block unit and execute them anytime you want. The code block is the function. You’ve seen functions in Storage.vy
. There are two functions in that file, the store function and the retrieve function.
As you did with the store function, you can create a function to set the values for the variables that you’ve declared. Then, you can call the function after deploying the smart contract to the blockchain. However, this brings us to the question, wouldn’t it be better if there was a function that would be executed automatically when the smart contract is deployed? There is a special function, called __init__
, just like in Python!
Create StorageInit.vy
and add the following code to it:
# @version ^0.3.0 my_grandma_wallet: address author: String[100] fib_list: int16[5] fib_dynamic_array: DynArray[int128, 5] struct Permission: ...