Skip to content
On this page

Operations and transactions โ€‹

Operations are usually handled through commands. They can sometimes be handled in a more functional manner with expressions.

Commands to Build Operations โ€‹

This is the usual method to build operations and is documented other pages.

See Contracts and Addresses for transfers and contract creation. See Keys for delegations. See Events for events.

Expressions to Build Operations โ€‹

This is rarely in practice but proves to be useful.

Contrary to operations built in commands, operations built in expressions need to be recorded explicitly within the contract. Otherwise, they are dropped.

Recording Operations โ€‹

sp.operations()

Return the current list of operations. This list can be manipulated freely in an entrypoint and serves as the list of recorded operations.

The compiler automatically reverses this list at the end of an entry point to respect the typical creation order of operations.

sp.add_operations(l)

Pushes a list of operations on top of the current list of operations.

It's an short-end for:

python
def add_operations(l):
    with sp.for_('op', l) as op:
        sp.operations().push(op)

Operations โ€‹

sp.transfer_operation(arg, amount, destination)

Return an expression that represents a transfer operation.

sp.set_delegate_operation(baker)

Return an expression that represents a set_delegate operation.

sp.create_contract_operation(contract,ย storageย =ย None,ย amountย = tez(0),ย bakerย =ย None)

Return an expression that represents a create_contract operation.

sp.emit_operation(event,ย with_typeย =ย True,ย tagย =ย None)

Return an expression that represents an emit operation.

In practice, SmartPy operation commands are built on top of these expressions:

python
def transfer(arg, amount, destination, line_no = None):
    operations().push(transfer_operation(arg, amount, destination, line_no))

def set_delegate(key_hash):
    operations().push(set_delegate_operation(key_hash))

def create_contract(contract, storage = None, amount = tez(0), baker = None):
    x = create_contract_operation(contract, storage, amount, baker)
    operations().push(x.operation)
    return x.address

def emit(event, tag = None, line_no = None):
    operations().push(emit_operation(event, tag, line_no))