compile_time

CreateNewEvent(arguments: list[tuple[str, type]] = [], event_name: str = '') Event

Creates a new Event.

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

>>> new_event: Event = CreateNewEvent(
...     [
...        ('name', str),
...        ('amount', int)
...     ],
...     'New Event'
... )
Parameters:
  • arguments (list[tuple[str, type]]) – the list of the events args’ names and types

  • event_name (str) – custom name of the event. It’s filled with the variable name if not specified

Returns:

the new event

Return type:

Event

public(name: str = None, safe: bool = False, *args, **kwargs)

This decorator identifies which methods should be included in the abi file. Adding this decorator to a function means it could be called externally.

>>> @public     # this method will be added to the abi
... def callable_function() -> bool:
...     return True
{
    "name": "callable_function",
    "offset": 0,
    "parameters": [],
    "safe": false,
    "returntype": "Boolean"
}
>>> @public(name='callableFunction')     # the method will be added with the different name to the abi
... def callable_function() -> bool:
...     return True
{
    "name": "callableFunction",
    "offset": 0,
    "parameters": [],
    "safe": false,
    "returntype": "Boolean"
}
>>> @public(safe=True)      # the method will be added with the safe flag to the abi
... def callable_function() -> bool:
...     return True
{
    "name": "callable_function",
    "offset": 0,
    "parameters": [],
    "safe": true,
    "returntype": "Boolean"
}
Parameters:
  • name (str) – Identifier for this method that’ll be used on the abi. If not specified, it’ll be the same identifier from Python method definition

  • safe (bool) – Whether this method is an abi safe method. False by default

contract(script_hash: str | bytes)

This decorator identifies a class that should be interpreted as an interface to an existing contract.

If you want to use the script hash in your code, you can use the hash class attribute that automatically maps the script hash parameter onto it. You don’t need to declare it in your class, but your IDE might send a warning about the attribute if you don’t.

Check out Our Documentation to learn more about this decorator.

>>> @contract('0xd2a4cff31913016155e38e474a2c06d08be276cf')
... class GASInterface:
...     hash: UInt160      # you don't need to declare this class variable, we are only doing it to avoid IDE warnings
...                        # but if you do declare, you need to import the type UInt160 from boa3.builtin.type
...     @staticmethod
...     def symbol() -> str:
...         pass
... @public
... def main() -> str:
...     return "Symbol is " + GASInterface.symbol()
... @public
... def return_hash() -> UInt160:
...     return GASInterface.hash    # neo3-boa will understand that this attribute exists even if you don't declare it
Parameters:

script_hash (str or bytes) – Script hash of the interfaced contract

display_name(name: str)

This decorator identifies which methods from a contract interface should have a different identifier from the one interfacing it. It only works in contract interface classes.

>>> @contract('0xd2a4cff31913016155e38e474a2c06d08be276cf')
... class GASInterface:
...     @staticmethod
...     @display_name('totalSupply')
...     def total_supply() -> int:      # the smart contract will call "totalSupply", but when writing the script you can call this method whatever you want to
...         pass
... @public
... def main() -> int:
...     return GASInterface.total_supply()
Parameters:

name (str) – Method identifier from the contract manifest.

class NeoMetadata

Bases: object

This class stores the smart contract manifest information.

Check out Neo’s Documentation to learn more about the Manifest.

>>> def neo_metadata() -> NeoMetadata:
...     meta = NeoMetadata()
...     meta.name = 'NewContractName'
...     meta.add_permission(methods=['onNEP17Payment'])
...     meta.add_trusted_source("0x1234567890123456789012345678901234567890")
...     meta.date = "2023/05/30"    # this property will end up inside the extra property
...     return meta
Variables:
  • name – the smart contract name. Will be the name of the file by default;

  • supported_standards (list[str]) – Neo standards supported by this smart contract. Empty by default;

  • permissions (list[str]) – a list of contracts and methods that this smart contract permits to invoke and call. All contracts and methods permitted by default;

  • trusts (list[str]) – a list of contracts that this smart contract trust. Empty by default;

  • author (str or None) – the smart contract author. None by default;

  • email (str or None) – the smart contract author email. None by default;

  • description (str or None) – the smart contract description. None by default;

property extras: dict[str, Any]

Gets the metadata extra information.

Returns:

a dictionary that maps each extra value with its name. Empty by default

add_trusted_source(hash_or_address: str)

Adds a valid contract hash, valid group public key, or the ‘*’ wildcard to trusts.

>>> self.add_trusted_source("0x1234567890123456789012345678901234abcdef")
>>> self.add_trusted_source("035a928f201639204e06b4368b1a93365462a8ebbff0b8818151b74faab3a2b61a")
>>> self.add_trusted_source("*")
Parameters:

hash_or_address (str) – a contract hash, group public key or ‘*’

add_group(pub_key: str, signature: str)

Adds a pair of public key and signature to the groups in the manifest.

>>> self.add_group("031f64da8a38e6c1e5423a72ddd6d4fc4a777abe537e5cb5aa0425685cda8e063b",
...                "fhsOJNF3N5Pm3oV1b7wYTx0QVelYNu7whwXMi8GsNGFKUnu3ZG8z7oWLfzzEz9pbnzwQe8WFCALEiZhLD1jG/w==")
Parameters:
  • pub_key (str) – public key of the group

  • signature (str) – signature of the contract hash encoded in Base64

add_permission(*, contract: str = '*', methods: list[str] | str | tuple[str, ...] = '*')

Adds a valid contract and a valid methods to the permissions in the manifest.

>>> self.add_permission(methods=['onNEP17Payment'])
>>> self.add_permission(contract='0x3846a4aa420d9831044396dd3a56011514cd10e3', methods=['get_object'])
>>> self.add_permission(contract='0333b24ee50a488caa5deec7e021ff515f57b7993b93b45d7df901e23ee3004916')
Parameters:
  • contract (str) – a contract hash, group public key or ‘*’

  • methods (list[str] or str) – a list of methods or ‘*’