contracts

Classes:

ContractManagement

A class used to represent the ContractManagement native contract.

CryptoLib

A class used to represent the CryptoLib native contract.

GasToken

A class used to represent the GAS native contract.

LedgerContract

A class used to represent the Ledger native contract.

NeoToken

A class used to represent the NEO native contract.

OracleContract

Neo Oracle Service is an out-of-chain data access service built into Neo N3.

PolicyContract

A class used to represent the Policy native contract.

RoleManagement

A class used to represent the RoleManagement native contract.

StdLib

A class used to represent StdLib native contract.

class ContractManagement

Bases: object

A class used to represent the ContractManagement native contract.

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

Methods:

get_minimum_deployment_fee

Gets the minimum fee of contract deployment.

get_contract

Gets a contract with a given hash.

has_method

Check if a method exists in a contract.

deploy

Creates a smart contract given the script and the manifest.

update

Updates the executing smart contract given the script and the manifest.

destroy

Destroy the executing smart contract.

classmethod get_minimum_deployment_fee() int

Gets the minimum fee of contract deployment.

>>> ContractManagement.get_minimum_deployment_fee()
1000000000
Returns:

the minimum fee of contract deployment

classmethod get_contract(script_hash: UInt160) Contract | None

Gets a contract with a given hash. If the script hash is not associated with a smart contract, then it will return None.

>>> ContractManagement.get_contract(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'))    # GAS script hash
{
    'id': -6,
    'update_counter': 0,
    'hash': b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2',
    'nef': b'NEF3neo-core-v3.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#\x10A\x1a\xf7{g@\x10A\x1a\xf7{g@\x10A\x1a\xf7{g@\x10A\x1a\xf7{g@\x10A\x1a\xf7{g@QA\xc7\x9e',
    'manifest': {
        'name': 'GasToken',
        'group': [],
        'supported_standards': ['NEP-17'],
        'abi': [[['balanceOf', [['account', 20]], 17, 0, True], ['decimals', [], 17, 7, True], ['symbol', [], 19, 14, True], ['totalSupply', [], 17, 21, True], ['transfer', [['from', 20], ['to', 20], ['amount', 17], ['data', 0]], 16, 28, False]], [['Transfer', [['from', 20], ['to', 20], ['amount', 17]]]]],
        'permissions': [[None, None]],
        'trusts': [],
        'extras': 'null'
    },
}
>>> ContractManagement.get_contract(UInt160(bytes(20)))    # there is no smart contract associated with this script hash
None
Parameters:

script_hash (boa3.sc.types.UInt160) – a smart contract hash

Returns:

a contract

Return type:

boa3.sc.type.Contract

Raises:

Exception – raised if hash length isn’t 20 bytes.

classmethod has_method(hash: UInt160, method: str, parameter_count: int) bool

Check if a method exists in a contract.

>>> ContractManagement.has_method(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'),
...                               'balanceOf', 1)    # GAS script hash
True
>>> ContractManagement.has_method(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'),
...                               'balanceOf', 10)    # GAS script hash
False
>>> ContractManagement.has_method(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'),
...                               'invalid', 1)    # GAS script hash
False
Parameters:
  • hash (boa3.sc.types.UInt160) – The hash of the deployed contract

  • method (str) – The name of the method

  • parameter_count (int) – The number of parameters

Returns:

whether the method exists or not

Return type:

bool

Raises:

Exception – raised if hash length isn’t 20 bytes or if the parameter_count is less than 0.

classmethod deploy(nef_file: bytes, manifest: bytes, data: Any = None) Contract

Creates a smart contract given the script and the manifest.

>>> nef_file_ = get_script(); manifest_ = get_manifest()    # get the script and manifest somehow
... ContractManagement.deploy(nef_file_, manifest_, None)             # smart contract will be deployed
{
    'id': 2,
    'update_counter': 0,
    'hash': b'\x92\x8f+1q\x86z_@\x94\xf5pE\xcb\xb8 \x0f\\`Z',
    'nef': b'NEF3neo3-boa by COZ-1.0.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\x07W\x00\x02xy\x9e@\xf9\7b\xbb\xcc',
    'manifest': {
        'name': 'TestContract',
        'group': [],
        'supported_standards': [],
        'abi': [[['test', [['a', 17], ['b', 17]], 17, 0, False]], []],
        'permissions': [],
        'trusts': [],
        'extras': 'null'
    },
}
Parameters:
  • nef_file (bytes) – the target smart contract’s compiled nef

  • manifest (bytes) – the manifest.json that describes how the script should behave

  • data (Any) – the parameters for the _deploy function

Returns:

the contract that was created

Return type:

boa3.sc.type.Contract

Raises:

Exception – raised if the nef or the manifest are not a valid smart contract.

classmethod update(nef_file: bytes, manifest: bytes, data: Any = None)

Updates the executing smart contract given the script and the manifest.

>>> nef_file_ = get_script(); manifest_ = get_manifest()    # get the script and manifest somehow
... ContractManagement.update(nef_file_, manifest_, None)             # smart contract will be updated
None
Parameters:
  • nef_file (bytes) – the new smart contract’s compiled nef

  • manifest (bytes) – the new smart contract’s manifest

  • data (Any) – the parameters for the _deploy function

Raises:

Exception – raised if the nef and the manifest are not a valid smart contract or the new contract is the same as the old one.

classmethod destroy()

Destroy the executing smart contract.

>>> ContractManagement.destroy()
None
class CryptoLib

Bases: object

A class used to represent the CryptoLib native contract.

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

Methods:

murmur32

Computes the hash value for the specified byte array using the murmur32 algorithm.

sha256

Encrypts a key using SHA-256.

ripemd160

Encrypts a key using RIPEMD-160.

keccak256

Computes the hash value for the specified byte array using the keccak256 algorithm.

verify_with_ecdsa

Using the elliptic curve, it checks if the signature of the message was originally produced by the public key.

bls12_381_add

Add operation of two bls12381 points.

bls12_381_deserialize

Deserialize a bls12381 point.

bls12_381_equal

Determines whether the specified points are equal.

bls12_381_mul

Mul operation of gt point and multiplier.

bls12_381_pairing

Pairing operation of g1 and g2.

bls12_381_serialize

Serialize a bls12381 point.

classmethod murmur32(data: bytes, seed: int) bytes

Computes the hash value for the specified byte array using the murmur32 algorithm.

>>> CryptoLib.murmur32(b'unit test', 0)
b"\x90D'G"
Parameters:
  • data (bytes) – the input to compute the hash code for

  • seed (int) – the seed of the murmur32 hash function

Returns:

the hash value

Return type:

bytes

classmethod sha256(key: Any) bytes

Encrypts a key using SHA-256.

>>> CryptoLib.sha256('unit test')
b'\xdau1>J\xc2W\xf8LN\xfb2\x0f\xbd\x01\x1cr@<\xf5\x93<\x90\xd2\xe3\xb8$\xd6H\x96\xf8\x9a'
>>> CryptoLib.sha256(10)
b'\x9c\x82r\x01\xb9@\x19\xb4/\x85pk\xc4\x9cY\xff\x84\xb5`M\x11\xca\xaf\xb9\n\xb9HV\xc4\xe1\xddz'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

classmethod ripemd160(key: Any) bytes

Encrypts a key using RIPEMD-160.

>>> CryptoLib.ripemd160('unit test')
b'H\x8e\xef\xf4Zh\x89:\xe6\xf1\xdc\x08\xdd\x8f\x01\rD\n\xbdH'
>>> CryptoLib.ripemd160(10)
b'\xc0\xda\x02P8\xed\x83\xc6\x87\xdd\xc40\xda\x98F\xec\xb9\x7f9\x98'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

classmethod keccak256(data: bytes) bytes

Computes the hash value for the specified byte array using the keccak256 algorithm.

>>> CryptoLib.keccak256(b'unit test')
b'\xe5\x26\x91\x5a\xff\x6f\x5e\x35\x9d\x64\xa3\xce\xf0\x6e\xf3\xdb\x9f\x4a\x89\x0e\x20\xd1\xa5\x19\x5e\x3a\x24\x29\x78\x7e\xec\xb7'
Parameters:

data (bytes) – the input to compute the hash code for

Returns:

computed hash

Return type:

bytes

classmethod verify_with_ecdsa(message: bytes, pubkey: ECPoint, signature: bytes, curve: NamedCurveHash) bool

Using the elliptic curve, it checks if the signature of the message was originally produced by the public key.

>>> CryptoLib.verify_with_ecdsa(b'unit test', ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'),
...                             b'wrong_signature', NamedCurveHash.SECP256R1SHA256)
False
Parameters:
  • message (bytes) – the encrypted message

  • pubkey (boa3.sc.types.ECPoint) – the public key that might have created the item

  • signature (bytes) – the signature of the item

  • curve (boa3.sc.type.NamedCurveHash) – the curve that will be used by the ecdsa

Returns:

a boolean value that represents whether the signature is valid

Return type:

bool

classmethod bls12_381_add(x: IBls12381, y: IBls12381) IBls12381

Add operation of two bls12381 points.

Parameters:
  • x (IBls12381) – The first point

  • y (IBls12381) – The second point

Returns:

the two points sum

Return type:

IBls12381

classmethod bls12_381_deserialize(data: bytes) IBls12381

Deserialize a bls12381 point.

Parameters:

data (bytes) – The point as byte array

Returns:

the deserialized point

Return type:

IBls12381

classmethod bls12_381_equal(x: IBls12381, y: IBls12381) bool

Determines whether the specified points are equal.

Parameters:
  • x (IBls12381) – The first point

  • y (IBls12381) – The second point

Returns:

whether the specified points are equal or not

Return type:

bool

classmethod bls12_381_mul(x: IBls12381, mul: bytes, neg: bool) IBls12381

Mul operation of gt point and multiplier.

Parameters:
  • x (IBls12381) – The point

  • mul (int) – Multiplier, 32 bytes, little-endian

  • neg (bool) – negative number

Returns:

the two points product

Return type:

IBls12381

classmethod bls12_381_pairing(g1: IBls12381, g2: IBls12381) IBls12381

Pairing operation of g1 and g2.

Parameters:
  • g1 (IBls12381) – The g1 point

  • g2 (IBls12381) – The g2 point

Returns:

the two points pairing

Return type:

IBls12381

classmethod bls12_381_serialize(g: IBls12381) bytes

Serialize a bls12381 point.

Parameters:

g (IBls12381) – The point to be serialized.

Returns:

the serialized point

Return type:

bytes

class GasToken

Bases: object

A class used to represent the GAS native contract.

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

Methods:

symbol

Gets the symbol of GAS.

decimals

Gets the amount of decimals used by GAS.

totalSupply

Gets the total token supply deployed in the system.

balanceOf

Get the current balance of an address.

transfer

Transfers an amount of GAS from one account to another.

classmethod symbol() str

Gets the symbol of GAS.

>>> GasToken.symbol()
'GAS'
Returns:

the GAS string.

Return type:

str

classmethod decimals() int

Gets the amount of decimals used by GAS.

>>> GasToken.decimals()
8
Returns:

the number 8.

Return type:

int

classmethod totalSupply() int

Gets the total token supply deployed in the system.

>>> GasToken.totalSupply()
5199999098939320
>>> GasToken.totalSupply()
5522957322800300
Returns:

the total token supply deployed in the system.

Return type:

int

classmethod balanceOf(account: UInt160) int

Get the current balance of an address.

>>> GasToken.balanceOf(UInt160(bytes(20)))
0
>>> GasToken.balanceOf(UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'))
1000000000
Parameters:

account (boa3.sc.types.UInt160) – the account’s address to retrieve the balance for

Returns:

the account’s balance

Return type:

int

classmethod transfer(from_address: UInt160, to_address: UInt160, amount: int, data: Any = None) bool

Transfers an amount of GAS from one account to another.

If the method succeeds, it will fire the Transfer event and must return true, even if the amount is 0, or from and to are the same address.

>>> GasToken.transfer(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6      #\xe1\x9096\x89U\xac\x13'),     # this script hash needs to have signed the transaction or block
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              10000, None)
True
>>> GasToken.transfer(UInt160(bytes(20)),
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              10000, None)
False
>>> GasToken.transfer(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6      #\xe1\x9096\x89U\xac\x13'),
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              -1, None)
False
Parameters:
  • from_address (boa3.sc.types.UInt160) – the address to transfer from

  • to_address (boa3.sc.types.UInt160) – the address to transfer to

  • amount (int) – the amount of GAS to transfer

  • data (Any) – whatever data is pertinent to the onNEP17Payment method

Returns:

whether the transfer was successful

Return type:

bool

Raises:

Exception – raised if from_address or to_address length is not 20 or if amount is less than zero.

class LedgerContract

Bases: object

A class used to represent the Ledger native contract.

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

Methods:

get_block

Gets the block with the given index or hash.

get_current_index

Gets the index of the current block.

get_current_hash

Gets the hash of the current block.

get_transaction

Gets a transaction with the given hash.

get_transaction_from_block

Gets a transaction from a block.

get_transaction_height

Gets the height of a transaction.

get_transaction_signers

Gets the VM state of a transaction.

get_transaction_vm_state

Gets the VM state of a transaction.

classmethod get_block(index_or_hash: int | UInt256) Block | None

Gets the block with the given index or hash.

>>> LedgerContract.get_block(0)        # first block
{
    'hash': b"S{\xed'\x85&\xf5\x93U=\xc1\xbf'\x95\xc4/\x80X\xdb\xd5\xa1-\x97q\x85\xe3I\xe5\x99cd\x04",
    'version': 0,
    'previous_hash': '\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',
    'merkle_root': '\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',
    'timestamp': 1468595301000,
    'nonce': 2083236893,
    'index': 0,
    'primary_index': 0,
    'next_consensus': b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    'transaction_count': 0,
}
>>> LedgerContract.get_block(UInt256(b"S{\xed'\x85&\xf5\x93U=\xc1\xbf'\x95\xc4/\x80X\xdb\xd5\xa1-\x97q\x85\xe3I\xe5\x99cd\x04"))        # first block
{
    'hash': b"S{\xed'\x85&\xf5\x93U=\xc1\xbf'\x95\xc4/\x80X\xdb\xd5\xa1-\x97q\x85\xe3I\xe5\x99cd\x04",
    'version': 0,
    'previous_hash': '\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',
    'merkle_root': '\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',
    'timestamp': 1468595301000,
    'nonce': 2083236893,
    'index': 0,
    'primary_index': 0,
    'next_consensus': b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    'transaction_count': 0,
}
>>> LedgerContract.get_block(9999999)      # block doesn't exist
None
>>> LedgerContract.get_block(UInt256(bytes(32)))   # block doesn't exist
None
Parameters:

index_or_hash (int or boa3.sc.types.UInt256) – index or hash identifier of the block

Returns:

the desired block, if exists. None otherwise

Return type:

boa3.sc.types.Block or None

classmethod get_current_index() int

Gets the index of the current block.

>>> LedgerContract.get_current_index()
10908937
>>> LedgerContract.get_current_index()
2108690
>>> LedgerContract.get_current_index()
3529755
Returns:

the index of the current block

Return type:

int

classmethod get_current_hash() UInt256

Gets the hash of the current block.

>>> LedgerContract.get_current_hash()
b'\x3e\x65\xe5\x4d\x75\x5a\x94\x90\xd6\x98\x3a\x77\xe4\x82\xaf\x7a\x38\xc9\x8c\x1a\xc6\xd9\xda\x48\xbd\x7c\x22\xb3\x2a\x9e\x34\xea'
Returns:

the hash of the current block

Return type:

boa3.sc.types.UInt256

classmethod get_transaction(hash_: UInt256) Transaction | None

Gets a transaction with the given hash.

>>> LedgerContract.get_transaction(UInt256(b'\xff\x7f\x18\x99\x8c\x1d\x10X{bA\xc2\xe3\xdf\xc8\xb0\x9f>\xd0\xd2G\xe3\xba\xd8\x96\xb9\x0e\xc1iS\xcdr'))
{
    'hash': b'\xff\x7f\x18\x99\x8c\x1d\x10X{bA\xc2\xe3\xdf\xc8\xb0\x9f>\xd0\xd2G\xe3\xba\xd8\x96\xb9\x0e\xc1iS\xcdr',
    'version': 0,
    'nonce': 2025056010,
    'sender': b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    'system_fee': 2028330,
    'network_fee': 1206580,
    'valid_until_block': 5761,
    'script': b'\x0c\x14\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04\x11\xc0\x1f\x0c\tbalanceOf\x0c\x14\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2Ab}[R',
}
>>> LedgerContract.get_transaction(UInt256(bytes(32)))   # transaction doesn't exist
None
Parameters:

hash (boa3.sc.types.UInt256) – hash identifier of the transaction

Returns:

the Transaction, if exists. None otherwise

classmethod get_transaction_from_block(block_hash_or_height: UInt256 | int, tx_index: int) Transaction | None

Gets a transaction from a block.

>>> LedgerContract.get_transaction_from_block(1, 0)
{
    'hash': b'\xff\x7f\x18\x99\x8c\x1d\x10X{bA\xc2\xe3\xdf\xc8\xb0\x9f>\xd0\xd2G\xe3\xba\xd8\x96\xb9\x0e\xc1iS\xcdr',
    'version': 0,
    'nonce': 2025056010,
    'sender': b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    'system_fee': 2028330,
    'network_fee': 1206580,
    'valid_until_block': 5761,
    'script': b'\x0c\x14\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04\x11\xc0\x1f\x0c\tbalanceOf\x0c\x14\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2Ab}[R',
}
>>> LedgerContract.get_transaction_from_block(UInt256(b'\x21|\xc2~U\t\x89^\x0c\xc0\xd29wl\x0b\xad d\xe1\xf5U\xd7\xf5B\xa5/\x8b\x8f\x8b\x22\x24\x80'), 0)
{
    'hash': b'\xff\x7f\x18\x99\x8c\x1d\x10X{bA\xc2\xe3\xdf\xc8\xb0\x9f>\xd0\xd2G\xe3\xba\xd8\x96\xb9\x0e\xc1iS\xcdr',
    'version': 0,
    'nonce': 2025056010,
    'sender': b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
    'system_fee': 2028330,
    'network_fee': 1206580,
    'valid_until_block': 5761,
    'script': b'\x0c\x14\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04\x11\xc0\x1f\x0c\tbalanceOf\x0c\x14\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2Ab}[R',
}
>>> LedgerContract.get_transaction_from_block(123456789, 0)     # height does not exist yet
None
>>> LedgerContract.get_transaction_from_block(UInt256(bytes(32)), 0)     # block hash does not exist
None
Parameters:
  • block_hash_or_height (boa3.sc.types.UInt256 or int) – a block identifier

  • tx_index (int) – the transaction identifier in the block

Returns:

the Transaction, if exists. None otherwise

classmethod get_transaction_height(hash_: UInt256) int

Gets the height of a transaction.

>>> LedgerContract.get_transaction_height(UInt256(b'\x28\x89\x4f\xb6\x10\x62\x9d\xea\x4c\xcd\x00\x2e\x9e\x11\xa6\xd0\x3d\x28\x90\xc0\xe5\xd4\xfc\x8f\xc6\x4f\xcc\x32\x53\xb5\x48\x01'))
2108703
>>> LedgerContract.get_transaction_height(UInt256(b'\x29\x41\x06\xdb\x4c\xf3\x84\xa7\x20\x4d\xba\x0a\x04\x03\x72\xb3\x27\x76\xf2\x6e\xd3\x87\x49\x88\xd0\x3e\xff\x5d\xa9\x93\x8c\xa3'))
10
>>> LedgerContract.get_transaction_height(UInt256(bytes(32)))   # transaction doesn't exist
-1
Parameters:

hash (boa3.sc.types.UInt256) – hash identifier of the transaction

Returns:

height of the transaction

classmethod get_transaction_signers(hash_: UInt256) list[Signer]

Gets the VM state of a transaction.

>>> LedgerContract.get_transaction_signers(UInt256(b'\x29\x41\x06\xdb\x4c\xf3\x84\xa7\x20\x4d\xba\x0a\x04\x03\x72\xb3\x27\x76\xf2\x6e\xd3\x87\x49\x88\xd0\x3e\xff\x5d\xa9\x93\x8c\xa3'))
[
    {
        "account": b'\xa6\xea\xb0\xae\xaf\xb4\x96\xa1\x1b\xb0|\x88\x17\xcar\xa5J\x00\x12\x04',
        "scopes": 1,
        "allowed_contracts": [],
        "allowed_groups": [],
        "rules": [],
    },
]
Parameters:

hash (boa3.sc.types.UInt256) – hash identifier of the transaction

Returns:

VM state of the transaction

classmethod get_transaction_vm_state(hash_: UInt256) VMState

Gets the VM state of a transaction.

>>> LedgerContract.get_transaction_vm_state(UInt256(b'\x29\x41\x06\xdb\x4c\xf3\x84\xa7\x20\x4d\xba\x0a\x04\x03\x72\xb3\x27\x76\xf2\x6e\xd3\x87\x49\x88\xd0\x3e\xff\x5d\xa9\x93\x8c\xa3'))
VMState.HALT
Parameters:

hash (boa3.sc.types.UInt256) – hash identifier of the transaction

Returns:

VM state of the transaction

class NeoToken

Bases: object

A class used to represent the NEO native contract.

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

Methods:

symbol

Gets the symbol of NEO.

decimals

Gets the amount of decimals used by NEO.

totalSupply

Gets the total token supply deployed in the system.

balanceOf

Get the current balance of an address.

transfer

Transfers an amount of GAS from one account to another.

get_gas_per_block

Gets the amount of GAS generated in each block.

unclaimed_gas

Gets the amount of unclaimed GAS in the specified account.

register_candidate

Registers as a candidate.

unregister_candidate

Unregisters as a candidate.

vote

Votes for a candidate.

get_all_candidates

Gets the registered candidates iterator.

un_vote

Removes the vote of the candidate voted.

get_candidates

Gets the list of all registered candidates.

get_candidate_vote

Gets votes from specific candidate.

get_committee

Gets all committee members list.

get_committee_address

Gets the address of the committee.

get_register_price

Gets the fees to be paid to register as a candidate.

get_next_block_validators

Gets validators list of the next block.

get_account_state

Gets the latest votes of the specified account.

classmethod symbol() str

Gets the symbol of NEO.

>>> NeoToken.symbol()
'NEO'
Returns:

the NEO string.

Return type:

str

classmethod decimals() int

Gets the amount of decimals used by NEO.

>>> NeoToken.decimals()
0
Returns:

the number 0.

Return type:

int

classmethod totalSupply() int

Gets the total token supply deployed in the system.

>>> NeoToken.totalSupply()
100000000
Returns:

the total token supply deployed in the system.

Return type:

int

classmethod balanceOf(account: UInt160) int

Get the current balance of an address.

>>> NeoToken.balanceOf(UInt160(bytes(20)))
0
>>> NeoToken.balanceOf(UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'))
100
Parameters:

account (boa3.sc.types.UInt160) – the account’s address to retrieve the balance for

Returns:

the account’s balance

Return type:

int

classmethod transfer(from_address: UInt160, to_address: UInt160, amount: int, data: Any = None) bool

Transfers an amount of GAS from one account to another.

If the method succeeds, it will fire the Transfer event and must return true, even if the amount is 0, or from and to are the same address.

>>> NeoToken.transfer(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6      #\xe1\x9096\x89U\xac\x13'),     # this script hash needs to have signed the transaction or block
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              10, None)
True
>>> NeoToken.transfer(UInt160(bytes(20)),
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              10, None)
False
>>> NeoToken.transfer(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6      #\xe1\x9096\x89U\xac\x13'),
...              UInt160(b'\xabv\xe2\xcb\xb0\x16,vG\x2f\x44Va\x10\x14\x19\xf3\xff\xa1\xe6'),
...              -1, None)
False
Parameters:
  • from_address (boa3.sc.types.UInt160) – the address to transfer from

  • to_address (boa3.sc.types.UInt160) – the address to transfer to

  • amount (int) – the amount of NEO to transfer

  • data (Any) – whatever data is pertinent to the onNEP17Payment method

Returns:

whether the transfer was successful

Return type:

bool

Raises:

Exception – raised if from_address or to_address length is not 20 or if amount is less than zero.

classmethod get_gas_per_block() int

Gets the amount of GAS generated in each block.

>>> NeoToken.get_gas_per_block()
500000000
Returns:

the amount of GAS generated

Return type:

int

classmethod unclaimed_gas(account: UInt160, end: int) int

Gets the amount of unclaimed GAS in the specified account.

>>> NeoToken.unclaimed_gas(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6 #\xe1\x9096\x89U\xac\x13'), 0)
100000000
>>> NeoToken.unclaimed_gas(UInt160(bytes(20), 0)
100000000
Parameters:
classmethod register_candidate(pubkey: ECPoint) bool

Registers as a candidate.

>>> NeoToken.register_candidate(ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'))
False
Parameters:

pubkey (boa3.sc.types.ECPoint) – The public key of the account to be registered

Returns:

whether the registration was a success or not

Return type:

bool

classmethod unregister_candidate(pubkey: ECPoint) bool

Unregisters as a candidate.

>>> NeoToken.unregister_candidate(ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'))
False
Parameters:

pubkey (boa3.sc.types.ECPoint) – The public key of the account to be unregistered

Returns:

whether the unregistration was a success or not

Return type:

bool

classmethod vote(account: UInt160, vote_to: ECPoint) bool

Votes for a candidate.

>>> NeoToken.vote(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6  #\xe1\x9096\x89U\xac\x13'), ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'))
False
Parameters:
classmethod get_all_candidates() Iterator

Gets the registered candidates iterator.

>>> NeoToken.get_all_candidates()
[]
Returns:

all registered candidates

Return type:

Iterator

classmethod un_vote(account: UInt160) bool

Removes the vote of the candidate voted. It would be the same as calling vote(account, None).

>>> NeoToken.un_vote(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6       #\xe1\x9096\x89U\xac\x13'))
False
Parameters:

account (boa3.sc.types.UInt160) – the account that is removing the vote

classmethod get_candidates() list[tuple[ECPoint, int]]

Gets the list of all registered candidates.

>>> NeoToken.get_candidates()
[]
Returns:

all registered candidates

Return type:

list[tuple[boa3.sc.types.ECPoint, int]]

classmethod get_candidate_vote(pubkey: ECPoint) int

Gets votes from specific candidate.

>>> NeoToken.get_candidate_vote(ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'))
100
>>> NeoToken.get_candidate_vote(ECPoint(bytes(32)))
-1
Returns:

Votes or -1 if it was not found.

Return type:

int

classmethod get_committee() list[ECPoint]

Gets all committee members list.

>>> NeoToken.get_committee()
[ b'\x02|\x84\xb0V\xc2j{$XG\x1em\xcfgR\xed\xd9k\x96\x88}x34\xe3Q\xdd\xfe\x13\xc4\xbc\xa2' ]
Returns:

all committee members

Return type:

list[boa3.sc.types.ECPoint]

classmethod get_committee_address() UInt160

Gets the address of the committee.

>>> NeoToken.get_committee_address()
UInt160(0x9273d3c792bce5eab4daac1c3ffdc1e83c4237f7)
Returns:

the address of the committee

Return type:

boa3.sc.types.UInt160

classmethod get_register_price() int

Gets the fees to be paid to register as a candidate.

>>> NeoToken.get_register_price()
100000000000
Returns:

the amount of the fees

Return type:

int

classmethod get_next_block_validators() list[ECPoint]

Gets validators list of the next block.

>>> NeoToken.get_next_block_validators()
[ b'\x02|\x84\xb0V\xc2j{$XG\x1em\xcfgR\xed\xd9k\x96\x88}x34\xe3Q\xdd\xfe\x13\xc4\xbc\xa2' ]
Returns:

the public keys of the validators

Return type:

list[boa3.sc.types.ECPoint]

classmethod get_account_state(account: UInt160) NeoAccountState

Gets the latest votes of the specified account.

>>> NeoToken.get_account_state(UInt160(b'\xc9F\x17\xba!\x99\x07\xc1\xc5\xd6     #\xe1\x9096\x89U\xac\x13'))
{
    'balance': 100,
    'height': 2,
    'vote_to': None,
}
Parameters:

account (boa3.sc.types.UInt160) – the specified account

Returns:

the state of the account

Return type:

NeoAccountState

class OracleContract

Bases: object

Neo Oracle Service is an out-of-chain data access service built into Neo N3. It allows users to request the external data sources in smart contracts, and Oracle nodes designated by the committee will access the specified data source then pass the result in the callback function to continue executing the smart contract logic.

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

Methods:

request

Requests an information from outside the blockchain.

get_price

Gets the price for an Oracle request.

classmethod request(url: str, request_filter: str | None, callback: str, user_data: Any, gas_for_response: int)

Requests an information from outside the blockchain.

This method just requests data from the oracle, it won’t return the result.

>>> OracleContract.request('https://dora.coz.io/api/v1/neo3/testnet/asset/0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
...                '', 'callback_name', None, 10 * 10 ** 8)
None
Parameters:
  • url (str) – External url to retrieve the data

  • request_filter (str or None) –

    Filter to the request.

    See JSONPath format https://github.com/atifaziz/JSONPath

  • callback (str) –

    Method name that will be as a callback.

    This method must be public and implement the following interface:

    (url: str, user_data: Any, code: int, result: bytes) -> None

  • user_data (Any) – Optional data. It’ll be returned as the same when the callback is called

  • gas_for_response (int) –

    Amount of GAS needed to run the callback method.

    It MUST NOT be specified as the user representation.

    If it costs 1 gas, this value must be 1_00000000 (with the 8 decimals)

classmethod get_price() int

Gets the price for an Oracle request.

>>> OracleContract.get_price()
50000000
Returns:

the price for an Oracle request

class PolicyContract

Bases: object

A class used to represent the Policy native contract.

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

Methods:

get_fee_per_byte

Gets the network fee per transaction byte.

get_exec_fee_factor

Gets the execution fee factor.

get_storage_price

Gets the storage price.

get_attribute_fee

Gets the fee for attribute.

is_blocked

Determines whether the specified account is blocked.

set_attribute_fee

Sets the fee for attribute.

classmethod get_fee_per_byte() int

Gets the network fee per transaction byte.

>>> PolicyContract.get_fee_per_byte()
1000
Returns:

the network fee per transaction byte

Return type:

int

classmethod get_exec_fee_factor() int

Gets the execution fee factor. This is a multiplier that can be adjusted by the committee to adjust the system fees for transactions.

>>> PolicyContract.get_exec_fee_factor()
30
Returns:

the execution fee factor

Return type:

int

classmethod get_storage_price() int

Gets the storage price.

>>> PolicyContract.get_storage_price()
100000
Returns:

the storage price

Return type:

int

classmethod get_attribute_fee(attribute_type: TransactionAttributeType) int

Gets the fee for attribute.

>>> PolicyContract.get_attribute_fee(TransactionAttributeType.HIGH_PRIORITY)
0
Returns:

the fee for attribute

Return type:

int

classmethod is_blocked(account: UInt160) bool

Determines whether the specified account is blocked.

>>> PolicyContract.is_blocked(UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'))
False
Parameters:

account (boa3.sc.types.UInt160) – the account to be checked

Returns:

whether the account is blocked or not

Return type:

bool

classmethod set_attribute_fee(attribute_type: TransactionAttributeType, value: int) None

Sets the fee for attribute. You need to sign the transaction using a committee member, otherwise, this function will throw an error.

>>> PolicyContract.set_attribute_fee(TransactionAttributeType.HIGH_PRIORITY, 10)
None
class RoleManagement

Bases: object

A class used to represent the RoleManagement native contract.

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

Methods:

get_designated_by_role

Gets the list of nodes for the specified role.

classmethod get_designated_by_role(role: Role, index: int) ECPoint

Gets the list of nodes for the specified role.

>>> RoleManagement.get_designated_by_role(Role.ORACLE, 0)
[]
Parameters:
  • role (boa3.sc.type.Role) – the type of the role

  • index (int) – the index of the block to be queried

Returns:

the public keys of the nodes

Return type:

boa3.sc.types.ECPoint

class StdLib

Bases: object

A class used to represent StdLib native contract.

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

Methods:

serialize

Serializes the given value into its bytes representation.

deserialize

Deserializes the given bytes value.

json_serialize

Serializes an item into a json.

json_deserialize

Deserializes a json into some valid type.

base64_decode

Decodes a string value encoded with base64.

base64_encode

Encodes a bytes value using base64.

base58_decode

Decodes a string value encoded with base58.

base58_encode

Encodes a bytes value using base58.

base58_check_decode

Converts the specified str, which encodes binary data as base-58 digits, to an equivalent bytes value.

base58_check_encode

Converts a bytes value to its equivalent str representation that is encoded with base-58 digits.

itoa

Converts the specific type of value to a decimal or hexadecimal string.

atoi

Converts a character string to a specific base value, decimal or hexadecimal.

memory_compare

Compares a memory with another one.

memory_search

Searches for a given value in a given memory.

classmethod serialize(item: Any) bytes

Serializes the given value into its bytes representation.

>>> StdLib.serialize('42')
b'(\x0242'
>>> StdLib.serialize(42)
b'!\x01*'
>>> StdLib.serialize([2, 3, 5, 7])
b'@\x04!\x01\x02!\x01\x03!\x01\x05!\x01\x07'
>>> StdLib.serialize({1: 1, 2: 1, 3: 2})
b'H\x03!\x01\x01!\x01\x01!\x01\x02!\x01\x01!\x01\x03!\x01\x02'
Parameters:

item (Any) – value to be serialized

Returns:

the serialized value

Return type:

bytes

Raises:

Exception – raised if the item’s type is not serializable.

classmethod deserialize(data: bytes) Any

Deserializes the given bytes value.

>>> StdLib.deserialize(b'(\x0242')
'42'
>>> StdLib.deserialize(b'!\x01*')
42
>>> StdLib.deserialize(b'@\x04!\x01\x02!\x01\x03!\x01\x05!\x01\x07')
[2, 3, 5, 7]
>>> StdLib.deserialize(b'H\x03!\x01\x01!\x01\x01!\x01\x02!\x01\x01!\x01\x03!\x01\x02')
{1: 1, 2: 1, 3: 2}
Parameters:

data (bytes) – serialized value

Returns:

the deserialized result

Return type:

Any

Raises:

Exception – raised when the date doesn’t represent a serialized value.

classmethod json_serialize(item: Any) str

Serializes an item into a json.

>>> StdLib.json_serialize({'one': 1, 'two': 2, 'three': 3})
'{"one":1,"two":2,"three":3}'
Parameters:

item (Any) – The item that will be serialized

Returns:

The serialized item

Return type:

str

Raises:

Exception – raised if the item is an integer value out of the Neo’s accepted range, is a dictionary with a bytearray key, or isn’t serializable.

classmethod json_deserialize(json: str) Any

Deserializes a json into some valid type.

>>> StdLib.json_deserialize('{"one":1,"two":2,"three":3}')
{'one': 1, 'three': 3, 'two': 2}
Parameters:

json (str) – A json that will be deserialized

Returns:

The deserialized json

Return type:

Any

Raises:

Exception – raised if jsons deserialization is not valid.

classmethod base64_decode(key: str) bytes

Decodes a string value encoded with base64.

>>> StdLib.base64_decode("dW5pdCB0ZXN0")
b"unit test"
Parameters:

key (str) – string value to be decoded

Returns:

the decoded string

Return type:

bytes

classmethod base64_encode(key: bytes) str

Encodes a bytes value using base64.

>>> StdLib.base64_encode(b'unit test')
b"dW5pdCB0ZXN0"
Parameters:

key (bytes) – bytes value to be encoded

Returns:

the encoded string

Return type:

str

classmethod base58_decode(key: str) bytes

Decodes a string value encoded with base58.

>>> StdLib.base58_decode('2VhL46g69A1mu')
b"unit test"
Parameters:

key (str) – string value to be decoded

Returns:

the decoded bytes

Return type:

bytes

classmethod base58_encode(key: bytes) str

Encodes a bytes value using base58.

>>> StdLib.base58_encode(b'unit test')
b"2VhL46g69A1mu"
Parameters:

key (bytes) – bytes value to be encoded

Returns:

the encoded string

Return type:

str

classmethod base58_check_decode(key: str) bytes

Converts the specified str, which encodes binary data as base-58 digits, to an equivalent bytes value. The encoded str contains the checksum of the binary data.

>>> StdLib.base58_check_decode('AnJcKqvgBwKxsjX75o')
b"unit test"
Parameters:

key (str) – string value to be decoded

Returns:

the decoded bytes

Return type:

bytes

classmethod base58_check_encode(key: bytes) str

Converts a bytes value to its equivalent str representation that is encoded with base-58 digits. The encoded str contains the checksum of the binary data.

>>> StdLib.base58_check_encode(b'unit test')
b"AnJcKqvgBwKxsjX75o"
Parameters:

key (bytes) – bytes value to be encoded

Returns:

the encoded string

Return type:

str

classmethod itoa(value: int, base: int = 10) str

Converts the specific type of value to a decimal or hexadecimal string. The default is decimal.

>>> StdLib.itoa(10)
'10'
>>> StdLib.itoa(123)
'123'
>>> StdLib.itoa(-1, 16)
'f'
>>> StdLib.itoa(15, 16)
'0f'
Parameters:
  • value (int) – the int value

  • base (int) – the value’s base

Returns:

the converted string

Return type:

int

classmethod atoi(value: str, base: int = 10) int

Converts a character string to a specific base value, decimal or hexadecimal. The default is decimal.

>>> StdLib.atoi('10')
10
>>> StdLib.atoi('123')
123
>>> StdLib.atoi('1f', 16)
31
>>> StdLib.atoi('ff', 16)
-1
Parameters:
  • value (str) – the int value as a string

  • base (int) – the value base

Returns:

the equivalent value

Return type:

int

Raises:

Exception – raised when base isn’t 10 or 16.

classmethod memory_compare(mem1: bytes | str, mem2: bytes | str) int

Compares a memory with another one.

>>> StdLib.memory_compare('abc', 'abc')
0
>>> StdLib.memory_compare('ABC', 'abc')
-1
>>> StdLib.memory_compare('abc', 'ABC')
1
Parameters:
  • mem1 (bytes or str) – a memory to be compared to another one

  • mem2 (bytes or str) – a memory that will be compared with another one

Returns:

-1 if mem1 precedes mem2, 0 if mem1 and mem2 are equal, 1 if mem1 follows mem2

Return type:

int

Searches for a given value in a given memory.

>>> StdLib.memory_search('abcde', 'a', 0)
0
>>> StdLib.memory_search('abcde', 'e', 0)
4
Parameters:
  • mem (bytes or str) – the memory

  • value (bytes or str) – the value

  • start (int) – the index the search should start from

  • backward (bool) – whether it should invert the memory

Returns:

the index of the value in the memory. Returns -1 if it’s not found

Return type:

int