Skip to main content
Version: Next

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.

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>.

type returnType = [list<operation>, int];
type contractParam =
| ["Reset", unit]
| ["Decrement", int]
| ["Increment", int];
@entry
const callContract = (_: unit, storage: int): returnType => {
const contractAddress: address = ("KT1FpuaoBHwXMXJ6zn3F4ZhpjpPZV28MAinz" as address);
const myContract: contract<contractParam> = Tezos.get_contract(contractAddress);
const contractArg: contractParam = Increment(4);
const operation = Tezos.transaction(contractArg, 0tez, myContract);
return [list([operation]), storage + 1]
}