Code Documentation

Classes

Account

class robonomicsinterface.Account(seed: Optional[str] = None, remote_ws: Optional[str] = None, type_registry: Optional[Dict[str, Dict[str, Union[str, Any]]]] = None, crypto_type: int = 1)

Dataclass to hold account info and node connection parameters

__init__(seed: Optional[str] = None, remote_ws: Optional[str] = None, type_registry: Optional[Dict[str, Dict[str, Union[str, Any]]]] = None, crypto_type: int = 1) None
Save node connection parameters and create a keypair to sign transactions and define address if seed was passed

as a parameter.

Parameters
  • seed – Account seed (mnemonic or raw) as a key to sign transactions.

  • remote_ws – Node url. Default node address is “wss://polkadot.rpc.robonomics.network”. Another address may be specified (e.g. “ws://127.0.0.1:9944” for local node).

  • type_registry – Types used in the chain. Defaults are the most frequently used in Robonomics.

  • crypto_type – Use KeypairType.SR25519 or KeypairType.ED25519 cryptography for generating the Keypair.

get_address() str

Determine account address if seed was passed when creating an instance

Returns

Account ss58 address

BaseClass

class robonomicsinterface.BaseClass(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Base class for different modules to initialize service_functions instance for further work.

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

ChainUtils

class robonomicsinterface.ChainUtils(remote_ws: Optional[str] = None, type_registry: Optional[Dict[str, Dict[str, Union[str, Any]]]] = None)

Various tools for obtaining information from the blockchain.

__init__(remote_ws: Optional[str] = None, type_registry: Optional[Dict[str, Dict[str, Union[str, Any]]]] = None)

Initiate ChainUtils class with node address passed as an argument.

Parameters
  • remote_ws – Node url. Default node address is “wss://polkadot.rpc.robonomics.network”. Another address may be specified (e.g. “ws://127.0.0.1:9944” for local node).

  • type_registry – Types used in the chain. Defaults are the most frequently used in Robonomics.

static _check_hash_valid(data_hash: str)

Check if the hash is valid.

Parameters

data_hash – Extrinsic hash.

Returns

Bool flag if the hash is valid.

get_block_hash(block_number: int) str

Get block hash by its number.

Parameters

block_number – Block number.

Returns

Block hash.

get_block_number(block_hash: str) int

Get block number by its hash.

Parameters

block_hash – Block hash.

Returns

Block number.

get_extrinsic_in_block(block: Union[int, str], extrinsic: Union[None, str, int] = None) Union[None, list, dict]

Get all extrinsics in block or a certain extrinsic if its block idx is specified.

Parameters
  • block – Block pointer. Either block number or block hash.

  • extrinsic – Extrinsic in this block. Either its hash or block extrinsic idx.

Returns

All extrinsics in block or a certain extrinsic if its idx was passed

CommonFunctions

class robonomicsinterface.CommonFunctions(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for common functions such as getting account information or transferring tokens

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

get_account_info(addr: Optional[str] = None, block_hash: Optional[str] = None) Dict[str, Union[int, Dict[str, int]]]

Get account information.

Parameters
  • addr – Explored account ss58 address. Account dataclass address if None.

  • block_hash – Retrieves data as of passed block hash.

Returns

Account information dictionary.

get_account_nonce(addr: Optional[str] = None) int

Get current account nonce.

Parameters

addr – Account ss58 address. Self address via private key is obtained if not passed.

:return Account nonce. Due to the feature of substrate-interface lib, to create an extrinsic with incremented

nonce, pass account’s current nonce. See https://github.com/polkascan/py-substrate-interface/blob/85a52b1c8f22e81277907f82d807210747c6c583/substrateinterface/base.py#L1535 for example.

transfer_tokens(target_address: str, tokens: int, nonce: Optional[int] = None) str

Send tokens to target address.

Parameters
Returns

Hash of the transfer transaction.

Datalog

class robonomicsinterface.Datalog(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for datalog chainstate queries and extrinsic executions.

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

erase(nonce: Optional[int] = None) str

Erase ALL datalog records of Account.

Parameters

nonce – Nonce of the transaction. Due to the feature of substrate-interface lib, to create an extrinsic with incremented nonce, pass account’s current nonce. See https://github.com/polkascan/py-substrate-interface/blob/85a52b1c8f22e81277907f82d807210747c6c583/substrateinterface/base.py#L1535 for example.

Returns

Hash of the datalog erase transaction.

get_index(addr: Optional[str] = None, block_hash: Optional[str] = None) Dict[str, int]

Get account datalog index dictionary.

Parameters
  • addr – ss58 type 32 address of an account which datalog index is to be obtained. If None, tries to get Account datalog index if keypair was created, else raises NoPrivateKey.

  • block_hash – Retrieves data as of passed block hash.

Returns

Tuple of form {‘start’: <int>, ‘end’: <int>}

get_item(addr: Optional[str] = None, index: Optional[int] = None, block_hash: Optional[str] = None) Optional[Tuple[int, Union[int, str]]]

Fetch datalog record of a provided account. Fetch self datalog if no address provided and interface was initialized with a seed.

Parameters
  • addr – ss58 type 32 address of an account which datalog is to be fetched. If None, tries to fetch self datalog if keypair was created, else raises NoPrivateKey.

  • index – record index. case int: fetch datalog by specified index case None: fetch latest datalog.

  • block_hash – Retrieves data as of passed block hash.

Returns

Tuple. Datalog of the account with a timestamp, None if no records.

record(data: str, nonce: Optional[int] = None) str

Write any string to datalog. It has 512 bytes length limit.

Parameters
Returns

Hash of the datalog record transaction.

Launch

class robonomicsinterface.Launch(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for sending launch transactions.

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

launch(target_address: str, parameter: str, nonce: Optional[int] = None) str

Send Launch command to device.

Parameters
Returns

Hash of the launch transaction.

Liability

class robonomicsinterface.Liability(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for interacting with Robonomics Liability. Create and finalize ones, get information.

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

create(technics_hash: str, economics: int, promisee: str, promisor: str, promisee_params_signature: str, promisor_params_signature: str, nonce: Optional[int] = None, promisee_signature_crypto_type: int = 1, promisor_signature_crypto_type: int = 1) Tuple[int, str]

Create a liability to ensure economical relationships between robots! This is a contract to be assigned to a promisor by promisee. As soon as the job is done and reported, the promisor gets his reward. This extrinsic may be submitted by another address, but there should be promisee and promisor signatures.

Parameters
  • technics_hash – Details of the liability, where the promisee order is described. Accepts any 32-bytes data or a base58 (Qm...) IPFS hash.

  • economicsPromisor reward in Weiners.

  • promiseePromisee (customer) ss58 address

  • promisorPromisor (worker) ss58 address

  • promisee_params_signature – An agreement proof. This is a private key signed message containing technics and economics. Both sides need to do this. Signed by promisee.

  • promisor_params_signature – An agreement proof. This is a private key signed message containing technics and economics. Both sides need to do this. Signed by promisor.

  • nonce – Account nonce. Due to the feature of substrate-interface lib, to create an extrinsic with incremented nonce, pass account’s current nonce. See https://github.com/polkascan/py-substrate-interface/blob/85a52b1c8f22e81277907f82d807210747c6c583/substrateinterface/base.py#L1535 for example.

  • promisee_signature_crypto_type – Crypto type used to create promisee account.

  • promisor_signature_crypto_type – Crypto type used to create promisor account.

Returns

New liability index and hash of the liability creation transaction.

finalize(index: int, report_hash: str, promisor: Optional[str] = None, promisor_signature_crypto_type: int = 1, promisor_finalize_signature: Optional[str] = None, nonce: Optional[int] = None) str

Report on a completed job to receive a deserved award. This may be done by another address, but there should be a liability promisor signature.

Parameters
  • index – Liability item index.

  • report_hash – IPFS hash of a report data (videos, text, etc.). Accepts any 32-bytes data or a base58 (Qm...) IPFS hash.

  • promisorPromisor (worker) ss58 address. If not passed, replaced with transaction author address.

  • promisor_signature_crypto_type – Crypto type used to create promisor account.

  • promisor_finalize_signature – ‘Job done’ proof. A message containing liability index and report data signed by promisor. If not passed, this message is signed by a transaction author which should be a promisor so.

  • nonce – Account nonce. Due to the feature of substrate-interface lib, to create an extrinsic with incremented nonce, pass account’s current nonce. See https://github.com/polkascan/py-substrate-interface/blob/85a52b1c8f22e81277907f82d807210747c6c583/substrateinterface/base.py#L1535 for example.

Returns

Liability finalization transaction hash

get_agreement(index: int, block_hash: Optional[str] = None) Optional[Dict[str, Union[Dict[str, Union[str, int]], str]]]

Fetch information about existing liabilities.

Parameters
  • index – Liability item index.

  • block_hash – Retrieves data as of passed block hash.

Returns

Liability information: technics, economics, promisee, promisor, signatures. None if no such liability.

get_latest_index(block_hash: Optional[str] = None) Optional[int]

Fetch the latest liability index.

Parameters

block_hash – Retrieves data as of passed block hash.

Returns

Latest liability index.

get_report(index: int, block_hash: Optional[str] = None) Optional[Dict[str, Union[int, str, Dict[str, str]]]]

Fetch information about existing liability reports.

Parameters
  • index – Reported liability item index.

  • block_hash – block_hash: Retrieves data as of passed block hash.

Returns

Liability report information: index, promisor, report, signature. None if no such liability report.

sign_liability(technics_hash: str, economics: int) str

Sign liability params approve message with a private key. This function is meant to sign technics and economics``details message to state the agreement of ``promisee and promisor. Both sides need to do this.

Parameters
  • technics_hash – Details of the liability, where the promisee order is described. Accepts any 32-bytes data or a base58 (Qm...) IPFS hash.

  • economicsPromisor reward in Weiners.

Returns

Signed message 64-byte hash in sting form.

sign_report(index: int, report_hash: str) str

Sing liability finalization parameters proof message with a private key. This is meant to state that the job is done by promisor.

Parameters
  • index – Liability item index.

  • report_hash – IPFS hash of a report data (videos, text, etc.). Accepts any 32-bytes data or a base58 (Qm...) IPFS hash.

Returns

Signed message 64-byte hash in sting form.

PubSub

class robonomicsinterface.PubSub(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for handling Robonomics pubsub rpc requests

WARNING: THIS MODULE IS UNDER CONSTRUCTION, USE AT YOUR OWN RISK! TO BE UPDATED SOON

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

connect(address: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, bool, int]]

Connect to peer and add it into swarm.

Parameters
  • address – Multiaddr address of the peer to connect to.

  • result_handler – Callback function that processes the result received from the node.

Returns

Success flag in JSON message.

get_listeners(result_handler: Optional[Callable] = None) Dict[str, Union[str, List[str], int]]

Returns a list of node addresses.

Parameters

result_handler – Callback function that processes the result received from the node.

Returns

List of node addresses in JSON message.

get_peer(result_handler: Optional[Callable] = None) Dict[str, Union[str, int]]

Returns local peer ID.

Returns

Local peer ID in JSON message.

listen(address: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, bool, int]]

Listen address for incoming connections.

Parameters
  • address – Multiaddr address of the peer to connect to.

  • result_handler – Callback function that processes the result received from the node.

Returns

Success flag in JSON message.

publish(topic_name: str, message: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, bool, int]]

Publish message into the topic by name.

Parameters
  • topic_name – Topic name.

  • message – Message to be published.

  • result_handler – Callback function that processes the result received from the node.

Returns

Success flag in JSON message.

subscribe(topic_name: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, int]]

Listen address for incoming connections.

Parameters
  • topic_name – Topic name to subscribe to.

  • result_handler – Callback function that processes the result received from the node.

Returns

Subscription ID in JSON message.

unsubscribe(subscription_id: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, bool, int]]

Unsubscribe for incoming messages from topic.

Parameters
  • subscription_id – Subscription ID obtained when subscribed.

  • result_handler – Callback function that processes the result received from the node.

Returns

Success flag in JSON message.

ReqRes

class robonomicsinterface.ReqRes(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for handling Robonomics reqres rpc requests

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

p2p_get(address: str, message: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, int]]

Returns for p2p rpc get response.

Parameters
  • address – Multiaddr address of the peer to connect to. For example: “/ip4/127.0.0.1/tcp/61240/<Peer ID of server>.” This ID may be obtained on node/server initialization.

  • message – Request message. GET for example.

  • result_handler – Callback function that processes the result received from the node. This function accepts one argument - response.

p2p_ping(address: str, result_handler: Optional[Callable] = None) Dict[str, Union[str, int]]

Returns for reqres p2p rpc ping to server response

Parameters
  • address – Multiaddr address of the peer to connect to. For example: “/ip4/127.0.0.1/tcp/61240/<Peer ID of server>.” This ID may be obtained on node/server initialization.

  • result_handler – Callback function that processes the result received from the node. This function accepts one argument - response.

RWS

class robonomicsinterface.RWS(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for interacting with Robonomics Web Services subscriptions

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, websocket address and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

bid(index: int, amount: int) str

Bid to win a subscription!

Parameters
  • index – Auction index.

  • amount – Your bid in Weiners.

Returns

Transaction hash.

get_auction(index: int, block_hash: Optional[str] = None) Optional[Dict[str, Union[str, int, Dict[str, Dict[str, Dict[str, int]]]]]]

Get information about subscription auction.

Parameters
  • index – Auction index.

  • block_hash – Retrieves data as of passed block hash.

Returns

Auction info.

get_auction_next(block_hash: Optional[str] = None) int

Get index of the next auction to be unlocked.

Parameters

block_hash – Retrieves data as of passed block hash.

Returns

Auction index.

get_auction_queue(block_hash: Optional[str] = None) List[Optional[int]]

Get an auction queue of Robonomics Web Services subscriptions.

Parameters

block_hash – Retrieves data as of passed block hash.

Returns

Auction queue of Robonomics Web Services subscriptions.

get_days_left(addr: Optional[str] = None, block_hash: Optional[str] = None) Union[int, bool]

Check if RWS subscription is still active for the address.

Parameters
  • addr – Possible subscription owner. If None - account address.

  • block_hash – Retrieves data as of passed block hash.

Returns

Number of days (including part a day) left if subscription is active, False if no active subscription, -1 for a Lifetime subscription.

get_devices(addr: Optional[str] = None, block_hash: Optional[str] = None) List[Optional[str]]

Fetch list of RWS added devices.

Parameters
  • addr – Subscription owner. If None - account address.

  • block_hash – Retrieves data as of passed block hash.

Returns

List of added devices. Empty if none.

get_ledger(addr: Optional[str] = None, block_hash: Optional[str] = None) Optional[Dict[str, Union[int, Dict[str, Dict[str, int]]]]]

Subscription information.

Parameters
  • addr – Subscription owner. If None - account address.

  • block_hash – Retrieves data as of passed block hash.

Returns

Subscription information. Empty if none.

is_in_sub(sub_owner_addr: str, addr: Optional[str] = None, block_hash: Optional[str] = None) bool

Check whether addr is a device of sub_owner_addr subscription.

Parameters
  • sub_owner_addr – Subscription owner address.

  • addr – Address to check. If None - account address.

  • block_hash – Retrieves data as of passed block hash.

Returns

True if addr is in sub_owner_addr device list, False otherwise.

set_devices(devices: List[str]) str

Set devices which are authorized to use RWS subscriptions held by the extrinsic author.

Parameters

devices – Devices authorized to use RWS subscriptions. Include in list.

Returns

Transaction hash.

ServiceFunctions

class robonomicsinterface.ServiceFunctions(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Class for custom queries, extrinsics and RPC calls to Robonomics parachain network.

__init__(account: robonomicsinterface.classes.account.Account, wait_for_inclusion: bool = True, return_block_num: bool = False, rws_sub_owner: Optional[str] = None)

Assign Account dataclass parameters and create an empty interface attribute for a decorator.

Parameters
  • account – Account dataclass with seed, remote_ws and node type_registry.

  • wait_for_inclusion – Whether wait for a transaction to included in block. You will get the hash anyway.

  • return_block_num – If set to True, any executed extrinsic function will return a tuple of form (<extrinsic_hash>, <block_number-idx>). ONLY WORKS WHEN wait_for_inclusion IS SET TO TRUE.

  • rws_sub_owner – Subscription owner address. If passed, all extrinsics will be executed via RWS subscriptions.

chainstate_query(module: str, storage_function: str, params: Optional[Union[List[Union[str, int]], str, int]] = None, block_hash: Optional[str] = None, subscription_handler: Optional[callable] = None) Any

Create custom queries to fetch data from the Chainstate. Module names and storage functions, as well as required parameters are available at https://parachain.robonomics.network/#/chainstate.

Parameters
  • module – Chainstate module.

  • storage_function – Storage function.

  • params – Query parameters. None if no parameters. Include in list, if several.

  • block_hash – Retrieves data as of passed block hash.

  • subscription_handler – Callback function that processes the updates of the storage query subscription. The workflow is the same as in substrateinterface lib. Calling method with this parameter blocks current thread! Example of subscription handler: https://github.com/polkascan/py-substrate-interface#storage-subscriptions

Returns

Output of the query in any form.

extrinsic(call_module: str, call_function: str, params: Optional[Dict[str, Any]] = None, nonce: Optional[int] = None) Union[str, Tuple[str, str]]

Create an extrinsic, sign&submit it. Module names and functions, as well as required parameters are available at https://parachain.robonomics.network/#/extrinsics.

Parameters
Returns

A tuple of form (<extrinsic_hash>, <block_number-idx>) if return_block_num and wait_for_inclusion in __init__ were set to True. String <extrinsic_hash> otherwise.

rpc_request(method: str, params: Optional[List[str]], result_handler: Optional[Callable]) Dict[str, Any]

Method that handles the actual RPC request to the Substrate node. The other implemented functions eventually use this method to perform the request.

Parameters
  • method – Method of the JSONRPC request.

  • params – A list containing the parameters of the JSONRPC request.

  • result_handler – Callback function that processes the result received from the node.

Returns

Result of the request.

subscribe_block_headers(callback: callable) dict

Get chain head block headers.

Returns

Chain head block headers.

Subscriber

class robonomicsinterface.Subscriber(account: robonomicsinterface.classes.account.Account, subscribed_event: robonomicsinterface.classes.subscriptions.SubEvent, subscription_handler: callable, pass_event_id: bool = False, addr: Optional[Union[List[str], str]] = None)

Class intended for use in cases when needed to subscribe on chainstate updates/events.

__init__(account: robonomicsinterface.classes.account.Account, subscribed_event: robonomicsinterface.classes.subscriptions.SubEvent, subscription_handler: callable, pass_event_id: bool = False, addr: Optional[Union[List[str], str]] = None) None

Initiates an instance for further use and starts a subscription for a selected action.

Parameters
  • account – Account dataclass with seed, remote_ws address and node type_registry.

  • subscribed_event – Event in substrate chain to be awaited. Choose from SubEvent class.

  • subscription_handler – Callback function that processes the updates of the storage. This function is meant to accept only one parameter by default (the new event description). It will receive (block_num, event_id) as a second parameter if pass_event_id is set to True.

  • pass_event_id – The subscription_handler will receive event ID as a second parameter if pass_event_id is True. Format is {block_number}-{event_idx}.

  • addr – ss58 type 32 address(-es) of an account(-s) which is(are) meant to be event target. If None, will subscribe to all such events never-mind target address(-es).

_event_callback(index_obj: Any, update_nr: int, subscription_id: int) Optional[bool]

Function, processing updates in event list storage. On update filters events to a desired account and passes the event description to the user-provided callback method.

Parameters
  • index_obj – Updated event list.

  • update_nr – Update counter. Increments every new update added. Starts with 0.

  • subscription_id – Subscription ID.

_subscribe_event() None

Subscribe to events targeted to a certain account (launch, transfer). Call subscription_handler when updated.

_target_address_in_event(event) bool

Return whether call callback function or not.

Parameters

event – Occurred chain event.

Returns

Whether call callback function or not.

cancel() None

Cancel subscription and join its thread.

Console tool

Due to the click usage, autodocumentation here is impossible. Better check out the code.

Exceptions

exception robonomicsinterface.exceptions.DigitalTwinMapException

No Digital Twin was created with this index or there is no such topic in Digital Twin map.

exception robonomicsinterface.exceptions.InvalidExtrinsicHash

Invalid extrinsic hash format. Hash length is not 66 signs, or it doesn’t start from 0x.

exception robonomicsinterface.exceptions.NoPrivateKeyException

No private key was provided so unable to perform any operations requiring message signing.

Decorators

robonomicsinterface.decorators.check_socket_opened(func)

Open and substrate node connection each time needed.

Parameters

func – wrapped function.

Returns

wrapped function after augmentations.

Utils

robonomicsinterface.utils.create_keypair(seed: str, crypto_type: int = 1) substrateinterface.keypair.Keypair

Create a keypair for further use.

Parameters
  • seed – Account seed (mnemonic or raw) as a key to sign transactions. //Alice, //Bob etc. supported.

  • crypto_type – Use KeypairType.SR25519 or KeypairType.ED25519 cryptography for generating the Keypair.

Returns

A Keypair instance used by substrate to sign transactions.

robonomicsinterface.utils.dt_encode_topic(topic: str) str

Encode any string to be accepted by Digital Twin setSource. Use byte encoding and sha256-hashing.

Parameters

topic – Topic name to be encoded.

Returns

Hashed-encoded topic name

robonomicsinterface.utils.ipfs_32_bytes_to_qm_hash(string_32_bytes: str) str

Transform 32 bytes sting (without 2 heading bytes) to an IPFS base58 Qm… hash.

Parameters

string_32_bytes – 32 bytes sting (without 2 heading bytes).

Returns

IPFS base58 Qm… hash.

robonomicsinterface.utils.ipfs_qm_hash_to_32_bytes(ipfs_qm: str) str

Transform IPFS base58 Qm… hash to a 32 bytes sting (without 2 heading ‘0x’ bytes).

Parameters

ipfs_qm – IPFS base58 Qm… hash.

Returns

32 bytes sting (without 2 heading bytes).

robonomicsinterface.utils.str_to_scalebytes(data: Union[int, str], type_str: str) scalecodec.base.ScaleBytes

Encode string to a desired ScaleBytes data.

Parameters
  • data – String to encode.

  • type_str – Type (U32, Compact<Balance>, etc.).

Returns

ScaleBytes object

robonomicsinterface.utils.web_3_auth(seed: str) Tuple[str, str]

Get authentication header for a Web3-auth IPFS gateway.

Parameters

seed – Substrate account seed in any, mnemonic or raw form.

Returns

Authentication header.