Contracts
Syntax
Contract :
contract
IDENTIFIER{
ContractMember*
_}
ContractMember:
Visibility?
(
ContractField
| Function
| Struct
| Event
| Enum
)Visibility :
pub
?ContractField :
IDENTIFIER:
Type
A contract is a piece of EVM Code associated with an Account. See Appendix A. in the Yellow Paper for more info. In Fe, a contract is denoted using the contract
keyword. A contract definition adds a new contract type to the module. This contract type may be used for calling existing contracts with the same interface or initializing new contracts with the create methods.
An example of a contract
:
struct Signed {
pub book_msg: String<100>
}
contract GuestBook {
messages: Map<address, String<100>>
pub fn sign(mut self, mut ctx: Context, book_msg: String<100>) {
self.messages[ctx.msg_sender()] = book_msg
ctx.emit(Signed(book_msg: book_msg))
}
pub fn get_msg(self, addr: address) -> String<100> {
return self.messages[addr].to_mem()
}
}