runtime

check_witness(hash_or_pubkey: Union[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 (UInt160 or 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: Optional[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_trigger() TriggerType

Return the smart contract trigger type.

>>> get_trigger()
TriggerType.APPLICATION
Returns:

a value that represents the contract trigger type

Return type:

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 (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: Sequence = (), flags: CallFlags = CallFlags.NONE) Any

Loads a script at runtime.

>>> from typing import cast
... from boa3.builtin.vm import Opcode
... 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: Any

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,
]

Subpackages

class Notification

Bases: object

Represents a notification.

Variables:
  • script_hash (UInt160) – the script hash of the notification sender

  • event_name (str) – the notification’s name

  • state (tuple) – a tuple value storing all the notification contents.

class TriggerType(value)

Bases: IntFlag

Represents the triggers for running smart contracts. Triggers enable the contract to execute different logic under different usage scenarios.

Check out Neo’s Documentation to learn more about TriggerTypes.

ON_PERSIST

Indicate that the contract is triggered by the system to execute the OnPersist method of the native contracts.

POST_PERSIST

Indicate that the contract is triggered by the system to execute the PostPersist method of the native contracts.

SYSTEM

The combination of all system triggers.

VERIFICATION

Indicates that the contract is triggered by the verification of a IVerifiable.

APPLICATION

Indicates that the contract is triggered by the execution of transactions.

ALL

The combination of all triggers.