Contracts

Syntax
Contract :
   contract IDENTIFIER : NEWLINE
   INDENT
   ContractMember*
   DEDENT

ContractMember:
   Visibility?
   (
         ContractField
      | Function
      | Struct
      | Event
      | Enumeration
   )

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:

contract GuestBook:
    messages: Map<address, String<100>>

    event Signed:
        book_msg: String<100>

    pub fn sign(self, book_msg: String<100>):
        self.messages[msg.sender] = book_msg
        emit Signed(book_msg=book_msg)

    pub fn get_msg(self, addr: address) -> String<100>:
        return self.messages[addr].to_mem()