Skip to content
On this page

Addresses and contracts

Addresses

Addresses in SmartPy are of type sp.address. They are written as e.g. sp.address("tz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyU") or sp.address("KT1AafHA1C1vk959wvHWBispY9Y2f3fxBUUo").

The address can carry an entrypoint name, for example: sp.address("KT1AafHA1C1vk959wvHWBispY9Y2f3fxBUUo%approve").

sp.self_address() → sp.address

sp.self_address() returns the address of the contract onto which it is used.

Contracts

For contract definition, see Overview#Contracts.

Contracts are represented with the type sp.contract and are constructed with the sp.contract(type, address, entrypoint) instruction.

sp.contract(type, address) → sp.option[sp.contract[t]]
sp.contract(type, address, entrypoint) → sp.option[sp.contract[t]]

Returns a sp.Some(sp.contract[t]) if this contract exists, None otherwise.

If given, the entrypoint parameter must be named and be a constant string. For example, sp.contract(sp.nat, sp.address("KT1xxxx"), entrypoint="approve")

If the entrypoint parameter is absent, the entrypoint is taken from the address. If the address doesn't contain one, the entrypoint is "default".

sp.self_entrypoint(entrypoint_name) → sp.contract[t]

sp.self_entrypoint(entrypoint_name) returns a sp.contract[t] corresponding to contract's entrypoint.

The entrypoint_name argument must be a constant string, not an expression.

sp.to_address(c: sp.contract[t]) → sp.address

sp.to_address(c) returns the address corresponding to contract c.

If the sp.contract[t] designates a specific entrypoint, the entrypoint will be conserved in the address. For example: sp.address("KT1AafHA1C1vk959wvHWBispY9Y2f3fxBUUo%approve").