Back
Lesson 12:
Structs
Introduction to Vyper structs
Progress: 0%
Visit desktop version for better experiences.
Structs
Structs are custom data types to define a group of variables. They can be used inside mappings and arrays.
Struct members can be accessed via struct.argument_name
.
# pragma version 0.4.0
struct ExampleStruct:
sender_address: address
amount_sent: uint256
exampleStruct: public(ExampleStruct)
# State modifying function to update struct variable
@external
def modify_struct_variable(amount: uint256):
self.exampleStruct.sender_address = msg.sender
self.exampleStruct.amount_sent = amount
# Getter function to return struct variable
@external
@view
def get_struct_variable() -> ExampleStruct:
return self.exampleStruct