Structure of a Contract¶
Contracts in Vyper are contained within files, with each file being one smart-contract. Files in Vyper are similar to classes in object-oriented languages. Each file can contain declarations of State Variables, Functions, and structure-structs-types.
State Variables¶
State variables are values which are permanently stored in contract storage.
storedData: int128
See the Types section for valid state variable types and visibility-and-getters for possible choices for visibility.
Functions¶
Functions are the executable units of code within a contract.
@public
@payable
def bid(): // Function
// ...
Function-calls can happen internally or externally and have different levels of visibility (visibility-and-getters) towards other contracts. Functions must be decorated with either @public or @private.
Events¶
Events may be logged in specially indexed data structures that allow clients, including light clients, to efficiently search for them.
Payment: event({amount: int128, arg2: indexed(address)})
total_paid: int128
@public
@payable
def pay():
self.total_paid += msg.value
log.Payment(msg.value, msg.sender)
Events must be declared before global declarations and function definitions.