blockchain

get_contract(hash: UInt160) boa3.builtin.interop.contract.contract.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.

>>> 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'
    },
}
>>> get_contract(UInt160(bytes(20)))    # there is no smart contract associated with this script hash
None
Parameters:

hash (UInt160) – a smart contract hash

Returns:

a contract

Return type:

Contract

Raises:

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

get_block(index_or_hash: int | boa3.builtin.type.UInt256) boa3.builtin.interop.blockchain.block.Block | None

Gets the block with the given index or hash. Will return None if the index or hash is not associated with a Block.

>>> 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,
}
>>> 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,
}
>>> get_block(9999999)      # block doesn't exist
None
>>> get_block(UInt256(bytes(32)))   # block doesn't exist
None
Parameters:

index_or_hash (int or UInt256) – index or hash identifier of the block

Returns:

the desired block, if exists. None otherwise

Return type:

Block or None

get_transaction(hash_: UInt256) boa3.builtin.interop.blockchain.transaction.Transaction | None

Gets a transaction with the given hash. Will return None if the hash is not associated with a Transaction.

>>> 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',
}
>>> get_transaction(UInt256(bytes(32)))   # transaction doesn't exist
None
Parameters:

hash (UInt256) – hash identifier of the transaction

Returns:

the Transaction, if exists. None otherwise

get_transaction_from_block(block_hash_or_height: boa3.builtin.type.UInt256 | int, tx_index: int) boa3.builtin.interop.blockchain.transaction.Transaction | None

Gets a transaction from a block. Will return None if the block hash or height is not associated with a Transaction.

>>> 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',
}
>>> get_transaction_from_block(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'), 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',
}
>>> get_transaction_from_block(123456789, 0)     # height does not exist yet
None
>>> get_transaction_from_block(UInt256(bytes(32)), 0)     # block hash does not exist
None
Parameters:
  • block_hash_or_height (UInt256 or int) – a block identifier

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

Returns:

the Transaction, if exists. None otherwise

get_transaction_height(hash_: UInt256) int

Gets the height of a transaction. Will return -1 if the hash is not associated with a Transaction.

>>> 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
>>> 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
>>> get_transaction_height(UInt256(bytes(32)))   # transaction doesn't exist
-1
Parameters:

hash (UInt256) – hash identifier of the transaction

Returns:

height of the transaction

get_transaction_signers(hash_: UInt256) list[boa3.builtin.interop.blockchain.signer.Signer]

Gets a list with the signers of a transaction.

>>> 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 (UInt256) – hash identifier of the transaction

Returns:

VM state of the transaction

get_transaction_vm_state(hash_: UInt256) VMState

Gets the VM state of a transaction.

>>> 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 (UInt256) – hash identifier of the transaction

Returns:

VM state of the transaction

current_hash: UInt256

Gets the hash of the current block.

>>> 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'
current_index: int

Gets the index of the current block.

>>> current_index
10908937
>>> current_index
2108690
>>> current_index
3529755

Subpackages

class Block

Bases: object

Represents a block.

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

Variables:
  • hash (UInt256) – a unique identifier based on the unsigned data portion of the object

  • version (int) – the data structure version of the block

  • previous_hash (UInt256) – the hash of the previous block

  • merkle_root (UInt256) – the merkle root of the transactions

  • timestamp (int) – UTC timestamp of the block in milliseconds

  • nonce (int) – a random number used once in the cryptography

  • index (int) – the index of the block

  • next_consensus (UInt160) – the script hash of the consensus nodes that generates the next block

  • transaction_count (int) – the number of transactions on this block

class Signer

Bases: object

Represents a signer.

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

Variables:
class WitnessRule

Bases: object

Represents a witness rule.

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

Variables:
class WitnessCondition

Bases: object

Represents a witness condition.

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

Variables:

type (WitnessConditionType) –

class WitnessConditionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

BOOLEAN = 0
NOT = 1
AND = 2
OR = 3
SCRIPT_HASH = 24
GROUP = 25
CALLED_BY_ENTRY = 32
CALLED_BY_CONTRACT = 40
CALLED_BY_GROUP = 41
class WitnessRuleAction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

DENY = 0
ALLOW = 1
class WitnessScope(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntFlag

Determine the rules for a smart contract CheckWitness() sys call.

NONE = 0

No Contract was witnessed. Only sign the transaction.

CALLED_BY_ENTRY = 1

Allow the witness if the current calling script hash equals the entry script hash into the virtual machine. Using this prevents passing CheckWitness() in a smart contract called via another smart contract.

CUSTOM_CONTRACTS = 16

Allow the witness if called from a smart contract that is whitelisted in the signer allowed_contracts attribute.

CUSTOM_GROUPS = 32

Allow the witness if any public key is in the signer allowed_groups attribute is whitelisted in the contracts manifest.groups array.

WITNESS_RULES = 64

Allow the witness if the specified rules are satisfied

GLOBAL = 128

Allow the witness in all context. Equal to NEO 2.x’s default behaviour.

class Transaction

Bases: object

Represents a transaction.

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

Variables:
  • hash (UInt256) – a unique identifier based on the unsigned data portion of the object

  • version (int) – the data structure version of the transaction

  • nonce (int) – a random number used once in the cryptography

  • sender (UInt160) – the sender is the first signer of the transaction, they will pay the fees of the transaction

  • system_fee (int) – the fee paid for executing the script

  • network_fee (int) – the fee paid for the validation and inclusion of the transaction in a block by the consensus node

  • valid_until_block (int) – indicates that the transaction is only valid before this block height

  • script (bytes) – the array of instructions to be executed on the transaction chain by the virtual machine

class VMState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

Represents the VM execution state.

NONE

Indicates that the execution is in progress or has not yet begun.

HALT

Indicates that the execution has been completed successfully.

FAULT

Indicates that the execution has ended, and an exception that cannot be caught is thrown.

BREAK

Indicates that a breakpoint is currently being hit.