Syntax
Contract :
contractIDENTIFIER: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:
use std::context::Context
contract GuestBook:
messages: Map<address, String<100>>
event Signed:
book_msg: String<100>
pub fn sign(self, ctx: Context, book_msg: String<100>):
self.messages[ctx.msg_sender()] = book_msg
emit Signed(ctx, book_msg: book_msg)
pub fn get_msg(self, addr: address) -> String<100>:
return self.messages[addr].to_mem()