Skip to content
On this page

Global properties โ€‹

sender, source โ€‹

Consider a scenario involving two contracts, a receiver and a proxy. The contract proxy, transfers any amount received in a call to receiver. Assume a third contract bootstrap2 creates a transaction to the proxy contract sending 99 ๊œฉ . Then proxy creates an internal transaction that calls receiver:

INFO

SENDER_SOURCE

sp.sender and sp.source are of type sp.TAddress

python
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(sender = sp.none, source = sp.none)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.sender = sp.some(sp.sender)
        self.data.source = sp.some(sp.source)
Michelson SENDER

and

Michelson SOURCE

Get block timestamp โ€‹

Push the minimal injection time for the current block, namely the block whose validation triggered this execution. The minimal injection time is 60 seconds after the timestamp of the predecessor block. This value does not change during the execution of the contract.

It is of type sp.TTimestamp.

python
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(timestamp = sp.none)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.timestamp = sp.some(sp.now)
Michelson NOW

Get block level โ€‹

Gives the block level that included the operation.

It is of type sp.TNat.

python
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(level = sp.none)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.level = sp.some(sp.level)
Michelson LEVEL

Get chain identifier โ€‹

This instruction pushes on the stack the identifier of the chain on which the smart contract is executed.

The chain identifier is designed to prevent replay attacks between the main chain and the test chain forked during amendment exploration, where contract addresses and storages are identical.

The value is derived from the genesis block hash and will thus be different on the main chains of different networks and on the test chains on which the value depends on the first block of the test-chain.

It is of type sp.TChainId.

python
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(id = sp.none)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.id = sp.some(sp.chain_id)
Michelson CHAIN_ID

Get total voting power โ€‹

Return the total voting power of all contracts. The total voting power coincides with the sum of the rolls count of every contract in the voting listings. The voting listings is calculated at the beginning of every voting period.

It is of type sp.TNat.

python
import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self):
        self.init(total_voting_power = sp.none)

    @sp.entrypoint
    def entrypoint_1(self):
        self.data.total_voting_power = sp.some(sp.total_voting_power)
Michelson TOTAL_VOTING_POWER