/ hc-contract / docs / features.txt
features.txt
  1  Contracts
  2  
  3      Contracts are the main unit of code, containing types, entrypoints, and local functions.
  4      Only entrypoints can be called from outside the contract.
  5      Contracts can have a state type. The init entrypoint initializes the state.
  6  
  7  Calling other contracts
  8  
  9      Use a contract address of a specific contract type to call its entrypoints (e.g., v.vote(alt)).
 10      Optional named arguments for contract calls:
 11          gas: int - Sets a gas limit.
 12          value: int - Provides tokens to the call.
 13      Use Address.to_contract to convert an account address to a contract address.
 14      Access the underlying address of a contract instance using the address field (e.g., v.address).
 15  
 16  Protected contract calls
 17  
 18      Use the named argument protected: bool = true in a contract call to handle potential failures.
 19      Protected calls return an option type: Some(result) if successful, None if failed.
 20  
 21  Contract factories and child contracts
 22  
 23      Deploy new contracts using:
 24          Chain.clone(ref: 'c, gas: int, value: int, protected: bool, ...): if(protected) option('c) else 'c - Clones an existing contract.
 25          Chain.create(value: int, ...): 'c - Deploys a new contract instance.
 26      These functions take arguments matching the created contract's init function.
 27  
 28  Contract interfaces and polymorphism
 29  
 30      Contracts can implement interfaces, defining all entrypoints from the interface with compatible types.
 31      Interfaces can extend other interfaces.
 32      Rules for payable and stateful modifiers when implementing interfaces:
 33          payable can implement payable or non-payable.
 34          non-payable can only implement non-payable.
 35          payable entrypoint can implement payable or non-payable.
 36          non-payable entrypoint can only implement non-payable.
 37          non-stateful entrypoint can implement stateful or non-stateful.
 38          stateful entrypoint can only implement stateful.
 39  
 40  Mutable state
 41  
 42      Contracts can define a state type.
 43      Initial state is set by the init function.
 44      Access state using the implicit state variable.
 45      Update state using the put(new_state: state): unit function.
 46      Functions modifying state must be annotated with the stateful keyword.
 47  
 48  Payable
 49  
 50      Declare contracts as payable to allow receiving funds via Chain.spend or normal spend transactions.
 51      Declare entrypoints as payable to allow being called with a non-zero value.
 52      Check if an address is payable using Address.is_payable(addr): bool.
 53  
 54  Namespaces
 55  
 56      Use the namespace keyword to create libraries containing types and functions (not entrypoints).
 57      Access namespace members using qualification (e.g., Library.inc(x)).
 58      Use using Namespace to include a namespace in the current scope.
 59      Use using Namespace as Alias to create an alias for a namespace.
 60      Use using Namespace for [member1, member2] to import specific members.
 61      Use using Namespace hiding [member1, member2] to import everything except specified members.
 62  
 63  Splitting code over multiple files
 64  
 65      Use include "filename.aes" to include code from another file.
 66  
 67  Standard library
 68  
 69      Refer to the shrunk standard library documentation. Builtin namespaces are included by default. Others need explicit inclusion.
 70  
 71  Types
 72  
 73      int: Arbitrary-sized signed integer.
 74      char: Single character.
 75      address: æternity address (32 bytes).
 76      bool: Boolean.
 77      bits: Bit field.
 78      bytes(n): Fixed-size byte array.
 79      bytes(): Arbitrary-size byte array.
 80      string: Array of bytes.
 81      list: Homogeneous immutable singly linked list.
 82      ('a, 'b) => 'c: Function type.
 83      tuple: Ordered heterogeneous array.
 84      record: Immutable key-value store with fixed keys.
 85      map: Immutable key-value store with dynamic keys.
 86      option('a): Optional value (None or Some('a)).
 87      state: User-defined contract state type.
 88      event: Blockchain event (log entry).
 89      hash: 32-byte hash (bytes(32)).
 90      signature: 64-byte signature (bytes(64)).
 91      oracle('a, 'b): Oracle type.
 92      oracle_query('a, 'b): Oracle query type.
 93      contract: User-defined, typed contract address.
 94  
 95  Literals
 96  
 97      Provides examples for various literal types (unit, int, address, bool, bits, bytes, string, list, tuple, record, map, option, state, event, hash, signature, Chain.ttl, oracle, oracle_query, contract).
 98  
 99  Hole expression
100  
101      ???: Placeholder expression for type checking.
102  
103  Constants
104  
105      Contract-level or namespace-level immutable bindings.
106  
107  Arithmetic
108  
109      Supports +, -, *, /, mod, ^ for integers.
110      Supports bitwise operations: band, bor, bxor, bnot, <<, >>.
111  
112  Bit fields
113  
114      Alternative to bit arithmetic using the bits type (see standard library).
115  
116  Type aliases
117  
118      Use type keyword to create aliases (can be parameterized).
119  
120  Algebraic data types
121  
122      Use datatype to define variant types with constructors.
123      Use switch for pattern matching.