Contracts
The contract type represents a smart contract.
There is no way to create a literal value of this type; you must create a contract type by passing the address of the account to a predefined function.
Beware of failures if the address is invalid.
For information about the components of a contract and how to use them, see Contracts.
Creating contract types in contracts
The call Tezos.implicit_account(kh) casts the public key hash kh of an implicit account to a contract type that represents that user account.
Contract types that represent implicit accounts always have the type contract<unit> because they accept no parameter.
The call Tezos.get_contract(address) casts the address of a smart contract (originated account) to a contract type that represents that contract.
The type is parameterized based on the parameter that the contract accepts.
For example, if the contract accepts an integer, the type is contract<int>.
Creating contract types in tests
To create a contract type in a test, use the contract_of function, which accepts a namespace and returns a contract type.
See Testing.
Implicit types and functions
When declaring the entry points of a contract using @entry, LIGO generates two hidden values in the module:
- An implicit
mainfunction, which can be obtained using the keywordcontract_of(C)whereCis the namespace or module containing the entry points - The input type for that
mainfunction, which can be obtained using the keywordparameter_of(C)
In the example below, contract_of(C) returns the implicitly-declared main function that calls the increment or decrement entry points depending on the argument given, and parameter_of(C) is the variant ["Increment", int] | ["Decrement", int].