Skip to main content

Operation

transfer

The transfer instruction generates an operation.

This operation is either a simple transfer operation of a part of the contract balance to an account or a contract, or a call to another contract's entrypoint.

Transfer balance

The following transfers an amount a of tez to address c:

transfer a to c

It fails if amount a is greater than the contract balance.

Call another contract

Consider a contract with address c that declares an entrypoint e with argument of type T as follows:

entry e(x : T) { /* ... */ }

The following calls entrypoint e with argument value x of type T:

transfer a to c call e<T>(x)

It fails if amount a is greater than the contract balance or if contract c does not have entrypoint e with corresponding signature.

For example, consider the following contract:

archetype called_contract

variable r : nat = 0

entry exec(x : nat, y : nat) {
r := r * x + y
}

Then the following transfer instruction calls the exec entrypoint:

transfer 0tz to c call exec<nat * nat>((4,5))

Note that the multiple arguments of exec is turned into a tuple of corresponding values.

Call current contract

It is possible to call another entrypoint e of the current contract with the follwing instruction:

transfer a to entry self.e(x)

For example, the following would call the exec entrypoint from another entrypoint of the same contract:

transfer 0tz to entry self.exec(4,5)

Low level instruction

The transfer instruction is pre-compiled to the low level instruction make_operation.

The following instruction:

transfer a to c call e<T>(x)

is equivalent to:

const e ?= get_entrypoint<T>("%e", c) : "ENTRY_NOT_FOUND";
const o = make_operation(a, e, x);
operations := reverse(prepend(reverse(operations), o))

operations is the builtin list of operations returned by the entrypoint.

caution

Operations generated by the transfer instruction will be executed in the order transfer instructions appear in the code.

emit

The emit instruction emits an event of type T and value x:

emit<T>(x)

For example, consider the event declaration:

event HighestBidIncreased {
bidder : address;
amount : tez
}

Then the following emits the HighestBidIncreased event:

emit<HighestBidIncreased>({ source; transferred })

The low level instruction is make_event

See this blog entry for further information.

sandbox_exec

This instruction is used to exec a lambda typed lambda<list<ticket<nat * option<bytes>>>, list<operation>> in a sandbox contract for security reason: the contract that executes the lambda is the sandbox, not self.