neo3.api.noderpc
NEO RPC Node client and response classes.
ApplicationExecution
— SpecialisedExecutionResult
with additional notification and trigger information.BlockApplicationLogResponse
— Data log for processing of a block on chain.BlockValidator
— Activate consensus member.Candidate
— Candidate consensus member.ExecutionResult
— Execution result data.ExecutionResultResponse
— Response toinvokecontractverify
,invokefunction
orinvokescript
RPC call.GetPeersResponse
— Response togetpeers
RPC call.GetVersionResponse
— Response togetversion
RPC call.JsonRpcError
— Common base class for all non-exit exceptions.JsonRpcTimeoutError
— Common base class for all non-exit exceptions.MapStackItem
— Virtual machine stack item.MempoolResponse
— Response togetrawmempool
RPC call.NeoRpcClient
— Specialised RPC client for NEO's Node RPC API.Nep17Balance
— NEP-17 balance entry.Nep17BalancesResponse
— Response togetnep17balances
RPC call.Nep17Transfer
— NEP-17 transfer record.Nep17TransfersResponse
— Response togetnep17transfer
RPC call.NextBlockValidatorsResponse
— Response togetnextblockvalidators
RPC call.Notification
— Smart contract notification entry.Peer
— P2P peer information.RPCClient
— RPC Client base.Receipt
— Transaction receipt containing data regarding chain state and events happening as a result of executing the transaction.StackItem
— Virtual machine stack item.TransactionApplicationLogResponse
— Data log for processing of a transaction on chain.VersionProtocol
— Partial response ofgetversion
RPC call.
neo3.api.noderpc.
ApplicationExecution
(
state
, gas_consumed
, exception
, stack
, trigger
, notifications
)
Specialised ExecutionResult
with additional notification and trigger information.
neo3.api.noderpc.
BlockApplicationLogResponse
(
block_hash
, executions
)
Data log for processing of a block on chain.
Does not include the data log for its transactions.
neo3.api.noderpc.
BlockValidator
(
public_key
, votes
)
Activate consensus member.
neo3.api.noderpc.
Candidate
(
public_key
, votes
, active
)
Candidate consensus member.
neo3.api.noderpc.
ExecutionResult
(
state
, gas_consumed
, exception
, stack
)
Execution result data.
neo3.api.noderpc.
ExecutionResultResponse
(
state
, gas_consumed
, exception
, stack
, script
, notifications
)
Response to invokecontractverify
, invokefunction
or invokescript
RPC call.
neo3.api.noderpc.
GetPeersResponse
(
connected
, bad
, unconnected
)
Response to getpeers
RPC call.
neo3.api.noderpc.
GetVersionResponse
(
tcp_port
, ws_port
, nonce
, user_agent
, protocol
)
Response to getversion
RPC call.
neo3.api.noderpc.
JsonRpcError
(
code
, message
, data=None
)
Common base class for all non-exit exceptions.
neo3.api.noderpc.
JsonRpcTimeoutError
(
message=None
)
Common base class for all non-exit exceptions.
neo3.api.noderpc.
MapStackItem
(
type
, value
)
Virtual machine stack item.
as_address
(
)
(str) — Unwrap as NEO3 address.as_bool
(
)
(bool) — Unwrap asbool
.as_bytes
(
)
(bytes) — Unwrap asbool
.as_dict
(
)
(dict) — Unwrap asdict
.as_int
(
)
(int) — Unwrap asint
.as_list
(
)
(list) — Unwrap aslist
.as_none
(
)
— Unwrap asNone
.as_public_key
(
)
(ECPoint) — Unwrap asECPoint
.as_str
(
)
(str) — Unwrap asstr
.as_uint160
(
)
(UInt160) — Unwrap asUInt160
.as_uint256
(
)
(UInt256) — Unwrap asUInt256
.
as_address
(
)
→ str
Unwrap as NEO3 address.
as_bool
(
)
→ bool
Unwrap as bool
.
ValueError
— if internal item type does not match required.
as_bytes
(
)
→ bytes
Unwrap as bool
.
ValueError
— if internal item type does not match required.
as_dict
(
)
→ dict
Unwrap as dict
.
ValueError
— if internal item type does not match required.
as_int
(
)
→ int
Unwrap as int
.
ValueError
— if internal item type does not match required.
as_list
(
)
→ list
Unwrap as list
.
ValueError
— if internal item type does not match required.
as_none
(
)
Unwrap as None
.
ValueError
— if internal item type does not match required.
as_public_key
(
)
→ ECPoint
Unwrap as ECPoint
.
ValueError
— if internal item type does not match required.
as_str
(
)
→ str
Unwrap as str
.
ValueError
— if internal item type does not match required.
as_uint160
(
)
→ UInt160
Unwrap as UInt160
.
ValueError
— if internal item type does not match required.
as_uint256
(
)
→ UInt256
Unwrap as UInt256
.
ValueError
— if internal item type does not match required.
neo3.api.noderpc.
MempoolResponse
(
verified
, unverified
)
Response to getrawmempool
RPC call.
A verified transaction in the memory pool is a transaction which has had:
- - basic structural validation (e.g. max tx size)
- - signature validation
- - state validation
- block validity expiration check
- available balance vs network and system fees
- etc
neo3.api.noderpc.
NeoRpcClient
(
host
, **kwargs
)
Specialised RPC client for NEO's Node RPC API.
calculate_network_fee
(
tx
)
(int) — Obtain the cost of verifying the transaction and including it in a block (a.k.a network fee).close
(
)
— Close the client session.find_states
(
contract_hash
,prefix
)
(AsyncGenerator) — Fetch the smart contract storage state.get_application_log_block
(
block_hash
)
(BlockApplicationLogResponse) — Fetch the system event logs for a given block.get_application_log_transaction
(
tx_hash
)
(TransactionApplicationLogResponse) — Fetch the smart contract event logs for a given transaction.get_best_block_hash
(
)
(UInt256) — Fetch the hash of the highest block in the chain.get_block
(
index_or_hash
)
(Block) — Fetch the block by its index or block hash.get_block_count
(
)
(int) — Fetch the current height of the blockchain.get_block_hash
(
index
)
(UInt256) — Fetch the block hash by the block's index.get_block_header
(
index_or_hash
)
(Header) — Fetch the block header by its index or block hash.get_candidates
(
)
(Sequence) — Fetch list of consensus candidates.get_committee
(
)
(tuple) — Fetch the public keys of the current NEO committee.get_connection_count
(
)
(int) — Fetch the number of peers connected to the node.get_contract_state
(
contract_hash_or_name
)
(ContractState) — Fetch smart contract state information.get_nep17_balances
(
address
)
(Nep17BalancesResponse) — Fetch the balance of all NEP17 assets for the specified address.get_nep17_transfers
(
address
,start_time
,end_time
)
(Nep17TransfersResponse) — Fetch NEP17 transfers for a given address. Defaults to the last 7 days on the server side.get_next_blockvalidators
(
)
(NextBlockValidatorsResponse) — Fetch the list of next block validators.get_peers
(
)
(GetPeersResponse) — Fetch peer information.get_raw_mempool
(
)
(MempoolResponse) — Fetch the transaction hashes currently in the memory pool waiting to be added to the next produced block.get_storage
(
script_hash
,key
)
(bytes) — Fetch a value from a smart contracts storage by its key.get_transaction
(
tx_hash
)
(Transaction) — Fetch a transaction by its hash.get_transaction_height
(
tx_hash
)
(int) — Fetch the height of the block the transaction is included in.get_transaction_receipt
(
tx_hash
)
(Receipt) — Fetch a transaction receipt.get_unclaimed_gas
(
address
)
(int) — Fetch the amount of unclaimed gas for the given address.get_version
(
)
(GetVersionResponse) — Fetch the node client version, network protocol properties and network ports.invoke_contract_verify
(
contract_hash
,function_params
,signers
)
(ExecutionResultResponse) — Invoke theverify
method on the contract.invoke_function
(
contract_hash
,name
,function_params
,signers
)
(ExecutionResultResponse) — Invoke a smart contract function.invoke_script
(
script
,signers
)
(ExecutionResultResponse) — Execute a script in the virtual machine.print_contract_methods
(
contract_hash_or_name
)
— Helper to fetch all public methods of a smart contract, print their signatures in Python syntax asto help determine the right native argument types.send_block
(
block_
)
(UInt256) — Broadcast a transaction to the network.send_transaction
(
tx
)
(UInt256) — Broadcast a transaction to the network.validate_address
(
address
)
(bool) — Verify if the given address is valid for the network the node is running on.wait_for_transaction_receipt
(
tx_hash
,timeout
,retry_delay
)
(Receipt) — Try to fetch a transaction.
calculate_network_fee
(
tx
)
→ int
Obtain the cost of verifying the transaction and including it in a block (a.k.a network fee).
find_states
(
contract_hash
, prefix=None
)
Fetch the smart contract storage state.
contract_hash
(neo3.core.types.uint.uint160 | str) — the hash of the smart contract to call.prefix
(Optional, optional) — storage prefix to search for. If omitted will return all storage
a storage key/value pair
prints all deployed¶
prefix_contract_hash = b" " async with api.NeoRpcClient("https://testnet1.neo.coz.io:443") as client: async for k, v in client.find_states(CONTRACT_HASHES.MANAGEMENT, prefix_contract_hash): print(k, v)
get_application_log_block
(
block_hash
)
→ BlockApplicationLogResponse
Fetch the system event logs for a given block.
block_hash
(neo3.core.types.uint.uint256 | str) — the hash of the block to query for.
get_application_log_transaction
(
tx_hash
)
→ TransactionApplicationLogResponse
Fetch the smart contract event logs for a given transaction.
Commonly used to verify that a transaction sent via send_transaction()
was executed succesfully on chain.
tx_hash
(neo3.core.types.uint.uint256 | str) — the hash of the transaction to query for.
get_best_block_hash
(
)
→ UInt256
Fetch the hash of the highest block in the chain.
get_block
(
index_or_hash
)
→ Block
Fetch the block by its index or block hash.
get_block_count
(
)
→ int
Fetch the current height of the blockchain.
get_block_hash
(
index
)
→ UInt256
Fetch the block hash by the block's index.
get_block_header
(
index_or_hash
)
→ Header
Fetch the block header by its index or block hash.
get_candidates
(
)
→ Sequence
Fetch list of consensus candidates.
get_committee
(
)
→ tuple
Fetch the public keys of the current NEO committee.
get_connection_count
(
)
→ int
Fetch the number of peers connected to the node.
get_contract_state
(
contract_hash_or_name
)
→ ContractState
Fetch smart contract state information.
Note
Only native contracts can be queried by their name. Name is case-insensitive.
get_nep17_balances
(
address
)
→ Nep17BalancesResponse
Fetch the balance of all NEP17 assets for the specified address.
get_nep17_transfers
(
address
, start_time=None
, end_time=None
)
→ Nep17TransfersResponse
Fetch NEP17 transfers for a given address. Defaults to the last 7 days on the server side.
address
(str) — account to get transfer for.start_time
(Optional, optional) — if given the start of the requested range. Must be in UTC and time aware not naïve.end_time
(Optional, optional) — if given the end of the requested range.
Fetch transfers of the last 14 days¶
start = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=14)
await get_nep17_transfers(
get_next_blockvalidators
(
)
→ NextBlockValidatorsResponse
Fetch the list of next block validators.
get_peers
(
)
→ GetPeersResponse
Fetch peer information.
get_raw_mempool
(
)
→ MempoolResponse
Fetch the transaction hashes currently in the memory pool waiting to be added to the next produced block.
get_storage
(
script_hash
, key
)
→ bytes
Fetch a value from a smart contracts storage by its key.
Args: script_hash: contract script hash. key: the storage key to fetch the data for.
Example: # fetch the fee per byte from the Policy native contract key_fee_per_byte = b'
await client.get_storage(contracts.PolicyContract().hash, key_fee_per_byte)
get_transaction
(
tx_hash
)
→ Transaction
Fetch a transaction by its hash.
get_transaction_height
(
tx_hash
)
→ int
Fetch the height of the block the transaction is included in.
get_transaction_receipt
(
tx_hash
)
→ Receipt
Fetch a transaction receipt.
tx_hash
(UInt256) — unique identifier of the transaction to fetch receipt for.
get_unclaimed_gas
(
address
)
→ int
Fetch the amount of unclaimed gas for the given address.
address
(str) — a NEO address.
get_version
(
)
→ GetVersionResponse
Fetch the node client version, network protocol properties and network ports.
invoke_contract_verify
(
contract_hash
, function_params=None
, signers=None
)
→ ExecutionResultResponse
Invoke the verify
method on the contract.
Note
Calling smart contracts through this function does not alter the blockchain state.
The smart contract will be called using the Verification trigger (unlike the invoke_function
method
which uses the Application trigger).
contract_hash
(neo3.core.types.uint.uint160 | str) — the hash of the smart contract to call.function_params
(Optional, optional) — the arguments required by the smart contract function.signers
(Optional, optional) — additional signers (e.g. for checkwitness passing).
invoke_function
(
contract_hash
, name
, function_params=None
, signers=None
)
→ ExecutionResultResponse
Invoke a smart contract function.
Note
Calling smart contracts through this function does not alter the blockchain state.
To alter the blockchain state use the send_transaction
method instead.
contract_hash
(neo3.core.types.uint.uint160 | str) — the hash of the smart contract to call.name
(str) — the name of the function to call on the smart contract.function_params
(Optional, optional) — the arguments required by the smart contract function.signers
(Optional, optional) — additional signers (e.g. for checkwitness passing).
check if an account is blocked using the Policy native contract¶
policy_contract = "cc5e4edd9f5f8dba8bb65734541df7a1c081c67b" account_to_check = types.UInt160.from_string("86df72a6b4ab5335d506294f9ce993722253b6e2") signer_account = types.UInt160.from_string("f621168b1fce3a89c33a5f6bcf7e774b4657031c") signer = verification.Signer(signer_account, payloads.WitnessScope.CALLED_BY_ENTRY) await client.invoke_function(contract_hash=policy_contract, name="isBlocked", function_params=[account_to_check], signers=[signer])
invoke_script
(
script
, signers=None
)
Execute a script in the virtual machine.
Note
Executing VM scripts through this function does not alter the blockchain state.
script
(bytes) — an array of VM opcodes.signers
(Optional, optional) — additional signers (e.g. for checkwitness passing).
The results of executing the script in the VM.
print_contract_methods
(
contract_hash_or_name
)
Helper to fetch all public methods of a smart contract, print their signatures in Python syntax asto help determine the right native argument types.
Note
Only native contracts can be queried by their name. Name is case-insensitive.
send_block
(
block_
)
Broadcast a transaction to the network.
block_
(neo3.network.payloads.block.block | bytes) — either a Block object or a serialized Block.
a block hash if successful.
send_transaction
(
tx
)
Broadcast a transaction to the network.
Note
uses the sendrawtransaction
RPC method internally.
tx
(neo3.network.payloads.transaction.transaction | bytes) — either a Transaction object or a serialized Transaction. Must be signed.
a transaction hash if successful.
validate_address
(
address
)
→ bool
Verify if the given address is valid for the network the node is running on.
address
(str) — a NEO address.
wait_for_transaction_receipt
(
tx_hash
, timeout=20
, retry_delay=5
)
→ Receipt
Try to fetch a transaction.
tx_hash
(UInt256) — unique identifier of the transaction to fetch the receipt for.timeout
(float, optional) — maximum time to wait to find the transaction on chain in seconds.retry_delay
(float, optional) — interval between querying the chain for the transaction in seconds.
JsonRpcError
— for other errors that might occur.JsonRpcTimeoutError
— if timeout threshold is exceeded
close
(
)
Close the client session.
neo3.api.noderpc.
Nep17Balance
(
asset_hash
, amount
, last_updated_block
)
NEP-17 balance entry.
neo3.api.noderpc.
Nep17BalancesResponse
(
balances
, address
)
Response to getnep17balances
RPC call.
neo3.api.noderpc.
Nep17Transfer
(
time
, asset_hash
, transfer_address
, amount
, block_index
, transfer_notify_index
, tx_hash
)
NEP-17 transfer record.
neo3.api.noderpc.
Nep17TransfersResponse
(
sent
, received
, address
)
Response to getnep17transfer
RPC call.
neo3.api.noderpc.
NextBlockValidatorsResponse
(
validators
)
Response to getnextblockvalidators
RPC call.
neo3.api.noderpc.
Notification
(
contract
, event_name
, state
)
Smart contract notification entry.
neo3.api.noderpc.
Peer
(
address
, port
)
P2P peer information.
neo3.api.noderpc.
RPCClient
(
url
, timeout=3.0
)
RPC Client base.
close
(
)
— Close the client session.
close
(
)
Close the client session.
neo3.api.noderpc.
Receipt
(
tx_hash
, included_in_block
, confirmations
, execution
)
Transaction receipt containing data regarding chain state and events happening as a result of executing the transaction.
neo3.api.noderpc.
StackItem
(
type
, value
)
Virtual machine stack item.
as_address
(
)
(str) — Unwrap as NEO3 address.as_bool
(
)
(bool) — Unwrap asbool
.as_bytes
(
)
(bytes) — Unwrap asbool
.as_dict
(
)
(dict) — Unwrap asdict
.as_int
(
)
(int) — Unwrap asint
.as_list
(
)
(list) — Unwrap aslist
.as_none
(
)
— Unwrap asNone
.as_public_key
(
)
(ECPoint) — Unwrap asECPoint
.as_str
(
)
(str) — Unwrap asstr
.as_uint160
(
)
(UInt160) — Unwrap asUInt160
.as_uint256
(
)
(UInt256) — Unwrap asUInt256
.
as_address
(
)
→ str
Unwrap as NEO3 address.
as_bool
(
)
→ bool
Unwrap as bool
.
ValueError
— if internal item type does not match required.
as_bytes
(
)
→ bytes
Unwrap as bool
.
ValueError
— if internal item type does not match required.
as_dict
(
)
→ dict
Unwrap as dict
.
ValueError
— if internal item type does not match required.
as_int
(
)
→ int
Unwrap as int
.
ValueError
— if internal item type does not match required.
as_list
(
)
→ list
Unwrap as list
.
ValueError
— if internal item type does not match required.
as_none
(
)
Unwrap as None
.
ValueError
— if internal item type does not match required.
as_public_key
(
)
→ ECPoint
Unwrap as ECPoint
.
ValueError
— if internal item type does not match required.
as_str
(
)
→ str
Unwrap as str
.
ValueError
— if internal item type does not match required.
as_uint160
(
)
→ UInt160
Unwrap as UInt160
.
ValueError
— if internal item type does not match required.
as_uint256
(
)
→ UInt256
Unwrap as UInt256
.
ValueError
— if internal item type does not match required.
neo3.api.noderpc.
StackItemType
(
)
Virtual machine item types that can be found in the stack
property of responses when executing a script or transactions.
ANY
(str) — AnyARRAY
(str) — ArrayBOOL
(str) — BooleanBUFFER
(str) — BufferBYTE_STRING
(str) — ByteStringINTEGER
(str) — IntegerINTEROP_INTERFACE
(str) — InteropInterfaceMAP
(str) — MapPOINTER
(str) — PointerSTRUCT
(str) — Struct
neo3.api.noderpc.
TransactionApplicationLogResponse
(
tx_hash
, execution
)
Data log for processing of a transaction on chain.
neo3.api.noderpc.
VersionProtocol
(
address_version
, network
, validators_count
, ms_per_block
, max_traceable_blocks
, max_transactions_per_block
, max_valid_until_block_increment
, memorypool_max_transactions
, initial_gas_distribution
)
Partial response of getversion
RPC call.