runtime

Functions:

check_witness

Verifies that the transactions or block of the calling contract has validated the required script hash.

notify

Notifies the client from the executing smart contract.

log

Show log messages to the client from the executing smart contract.

get_current_signers

Get the Signers of the current transaction.

get_trigger

Return the smart contract trigger type.

get_notifications

This method gets current invocation notifications from specific 'script_hash'.

get_network

Gets the magic number of the current network.

burn_gas

Burns GAS to benefit the NEO ecosystem.

get_random

Gets the next random number.

load_script

Loads a script at runtime.

Data:

address_version

Gets the address version of the current network.

executing_script_hash

Gets the script hash of the current context.

calling_script_hash

Gets the script hash of the calling contract.

time

Gets the timestamp of the current block.

gas_left

Gets the remaining GAS that can be spent in order to complete the execution.

platform

Gets the name of the current platform.

invocation_counter

Gets the number of times the current contract has been called during the execution.

entry_script_hash

Gets the script hash of the entry context.

script_container

Gets the current script container.

check_witness(hash_or_pubkey: UInt160 | ECPoint) bool

Verifies that the transactions or block of the calling contract has validated the required script hash.

>>> check_witness(calling_script_hash)
True
>>> check_witness(UInt160(bytes(20)))
False
Parameters:

hash_or_pubkey (boa3.sc.types.UInt160 or boa3.sc.types.ECPoint) – script hash or public key to validate

Returns:

a boolean value that represents whether the script hash was verified

Return type:

bool

notify(state: Any, notification_name: str = None)

Notifies the client from the executing smart contract.

>>> var = 10
... notify(var)     # An event will be triggered
None
>>> var = 10
... notify(var, 'custom event name')     # An event will be triggered
None
Parameters:
  • state (Any) – the notification message

  • notification_name (str) – name that’ll be linked to the notification

log(message: str)

Show log messages to the client from the executing smart contract.

>>> log('log sent')     # An event that can be shown on the CLI
log sent
Parameters:

message (str) – the log message

get_current_signers() list[Signer]

Get the Signers of the current transaction.

Returns:

Return an array of all signers of the transaction.

Return type:

list[Signer]

get_trigger() TriggerType

Return the smart contract trigger type.

>>> get_trigger()
TriggerType.APPLICATION
Returns:

a value that represents the contract trigger type

Return type:

boa3.sc.types.TriggerType

get_notifications(script_hash: UInt160 = b'') list[Notification]

This method gets current invocation notifications from specific ‘script_hash’.

>>> notify(1); notify(2); notify(3)
... get_notifications(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'))
[
    [
        b'8\xfe\x11\n\xff7J\xb8}\xe9x6@\xea\x0b\x00\xf1|\x82v',
        'notify',
        [1]
    ],
    [
        b'8\xfe\x11\n\xff7J\xb8}\xe9x6@\xea\x0b\x00\xf1|\x82v',
        'notify',
        [2]
    ],
    [
        b'8\xfe\x11\n\xff7J\xb8}\xe9x6@\xea\x0b\x00\xf1|\x82v',
        'notify',
        [3]
    ]
]
Parameters:

script_hash (boa3.sc.types.UInt160) – must have 20 bytes, but if it’s all zero 0000…0000 it refers to all existing notifications (like a * wildcard)

Returns:

It will return an array of all matched notifications

Return type:

list[Notification]

get_network() int

Gets the magic number of the current network.

>>> get_network()
860243278
Returns:

the magic number of the current network

Return type:

int

burn_gas(gas: int)

Burns GAS to benefit the NEO ecosystem.

>>> burn_gas(1000)
None
Parameters:

gas (int) – the amount of GAS that will be burned

Raises:

Exception – raised if gas value is negative.

get_random() int

Gets the next random number.

>>> get_random()
191320526825634396960813166838892720709
>>> get_random()
99083669484001682562631729023191545809
>>> get_random()
328056213623902365838800581788496514419
Returns:

the next random number

Return type:

int

load_script(script: bytes, args: ~collections.abc.Sequence = (), flags: ~boa3.internal.neo3.contracts.contracttypes.CallFlags = <CallFlags.NONE: 0>) Any

Loads a script at runtime.

>>> from boa3.sc.types import Opcode    >>> from typing import cast
... cast(int, load_script(Opcode.ADD, [10, 2]))
12
address_version: int

Gets the address version of the current network.

>>> address_version
53
executing_script_hash: UInt160

Gets the script hash of the current context.

>>> executing_script_hash
b'^b]\x90#\xbf\xcc\x1f\xd8\x9e\xe3\xa4zd\x14\xa4\xf0\x96\x9f`'
calling_script_hash: UInt160

Gets the script hash of the calling contract.

>>> calling_script_hash
b'\x05\x7f\xc2\x9d\xba\xb2\xc1x\xf5\x81\x83\xbf\xcb\x87/\xc3!\xca\xe1\xd0'
time: int

Gets the timestamp of the current block.

>>> time
1685395697108
gas_left: int

Gets the remaining GAS that can be spent in order to complete the execution.

>>> gas_left
1999015490
platform: str

Gets the name of the current platform.

>>> platform
'NEO'
invocation_counter: int

Gets the number of times the current contract has been called during the execution.

>>> invocation_counter
1
entry_script_hash: UInt160

Gets the script hash of the entry context.

>>> entry_script_hash
b'\tK\xb31\xa8\x13\x80`\xad\xf6\xda\xdf\xc6R\x9b\xfdB\xbf\x83\x8f'
script_container: Transaction

Gets the current script container.

>>> script_container
[
    b'\xf1y\xc2\xd6\x1c\xb6\x98\xa4\xdc\xf3\xd67s\xd7E\xf0<;\x98+\xa2T\x03P,T\xe8\xc6{ \x101', 
    0, 
    442907905, 
    '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 
    0, 
    0, 
    0, 
    ''
]
>>> script_container
[
    b"S{\xed'\x85&\xf5\x93U=\xc1\xbf'\x95\xc4/\x80X\xdb\xd5\xa1-\x97q\x85\xe3I\xe5\x99cd\x04",
    0,
    '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
    '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
    1468595301000,
    2083236893,
    0,
    0,
    b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    0,
]