pypergraph package

Subpackages

Module contents

class pypergraph.DagAccount[source]

Bases: object

property address

Requires login. Get the DagAccount DAG address. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

Returns:

DAG address.

connect(network_id: str | None = 'mainnet', be_url: str | None = None, l0_host: str | None = None, cl1_host: str | None = None) DagAccount[source]

Configure the DagAccount network instance. Parameter ‘network_id’ can be used to change between ‘testnet’, ‘integrationnet’ or ‘mainnet’, without further parameter settings. Default: ‘mainnet’.

Parameters:
  • network_id – ‘mainnet’, ‘integrationnet’, ‘testnet’ or any string value.

  • be_url – Block Explorer host URL.

  • l0_host – Layer 0 host URL.

  • cl1_host – Currency Layer 1 host URL.

Returns:

Configured DagAccount object.

async create_allow_spend(destination: str, amount: int, approvers: List[str], source: str | None = None, fee: int = 0, currency_id: str | None = None, valid_until_epoch: int | None = None)[source]

Grants permission for another wallet or metagraph to spend up to a specified amount from the user’s wallet in a metagraph token or DAG.

Parameters:
  • source – Wallet address signing the transaction. Address of logged in account, if left None

  • destination – The destination address. This must be a Metagraph address.

  • amount – The amount the destination address is allowed to spend.

  • approvers – A list with single DAG address that can automatically approve the spend, can be Metagraph or wallet address.

  • currency_id – The Metagraph ID used to identify the currency. For DAG, this parameter is left None.

  • fee – Default 0.

  • valid_until_epoch – The global snapshot epoch progress for which this is valid until. If not provided, the default value will be currentEpoch + 30. Minumum allowed value: currentEpoch + 5. Maximum allowed value: currentEpoch + 60.

async create_delegate_stake()[source]
create_metagraph_token_client(account: Self | None = None, metagraph_id: str | None = None, block_explorer_url: str | None = None, l0_host: str | None = None, currency_l1_host: str | None = None, data_l1_host: str | None = None, token_decimals: int = 8)[source]

Derive a Metagraph client from the active account to interact with a Metagraph.

Parameters:
  • account – active DagAccount.

  • metagraph_id – Associated Metagraph $DAG address.

  • block_explorer_url – (Optional) Block Explorer URL (default: associated account).

  • l0_host – (Optional) Layer 0 host URL (port might be required).

  • cl1_host – (Optional) Layer 1 currency host URL (port might be required).

  • dl1_host – (Optional) Layer 1 data host URL (port might be required).

  • token_decimals – (Optional) 1 $DAG = 100000000 (default: 8)

Returns:

Metagraph token client object.

async create_token_lock(amount: int, fee: int = 0, unlock_epoch: int = None, source: str | None = None, currency_id: str | None = None)[source]

Token locking is used for:

Node collateral staking Delegated staking participation Governance requirements Time-based vesting or escrow models

Parameters:
  • source – The wallet signing the transaction. The logged in account is the default if left empty.

  • amount – The amount to lock.

  • currency_id – The Metagraph identifier address for the currency to lock. Leave None, if currency is DAG.

  • fee – The fee. Default when None is 0.

  • unlock_epoch – The global snapshot epoch progress to unlock the tokens. If provided, must be greater than the current epoch.

async generate_batch_transactions(transfers: List[dict], last_ref: dict | TransactionReference | None = None)[source]

Generate a batch of transactions to be transferred from the active account.

Parameters:
  • transfers – List of dictionaries, e.g. txn_data = [ {‘to_address’: to_address, ‘amount’: 10000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 5000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 2500000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 1, ‘fee’: 200000} ]

  • last_ref – (Optional) Dictionary or with the account’s last transaction hash and ordinal.

Returns:

List of transactions to be transferred (see: transfer_batch_transactions(transactions=))

async generate_signed_transaction(to_address: str, amount: int, fee: int = 0, last_ref: dict | TransactionReference | None = None) Tuple[SignedTransaction, str][source]

Generate a signed currency transaction from the currently active account.

Parameters:
  • to_address – Recipient DAG address.

  • amount – Integer with 8 decimals constituting the amount to transfer from the active account.

  • fee – (Optional) a minimum fee might be required if the active account is transaction limited.

  • last_ref – (Optional) The ordinal and hash of the last transaction from the active account.

Returns:

Signed transaction and the transaction hash.

async get_balance()[source]

Get the balance for the active account.

Returns:

async get_balance_for(address: str)[source]

Get balance for a given DAG address. Returned as integer with 8 decimals.

Parameters:

address – DAG address.

Returns:

0 or 8 decimal integer.

get_eth_address() str[source]
is_active()[source]

Check if any account is logged in.

Returns:

login_with_private_key(private_key: str)[source]

Login with a private key. Before transferring data or currency you need to login using a seed phrase or private key.

Parameters:

private_key – Private key.

Returns:

login_with_public_key(public_key: str)[source]

Login with public key. This method does not enable the account to transfer data or currency. See: login_with_seed_phrase(words=) or login_with_private_key(private_key=)

Parameters:

public_key

Returns:

login_with_seed_phrase(phrase: str)[source]

Login with a 12 word seed phrase. Before transferring data or currency you need to login using a seed phrase or private key.

Parameters:

phrase – 12 word seed phrase.

Returns:

logout()[source]

Logout the active account (delete key trio).

Returns:

property private_key

Requires login. Get the DagAccount private key. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

Returns:

Private key.

property public_key

Requires login. Get the DagAccount public key. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

This method does not support transfer of data or currency, due to missing private key.

Returns:

Public key.

async set_node_parameters()[source]
async transfer(to_address: str, amount: int, fee: int = 0, auto_estimate_fee=False) PendingTransaction | None[source]

Build currency transaction, sign and transfer from the active account.

Parameters:
  • to_address – DAG address

  • amount – Integer with 8 decimals (e.g. 100000000 = 1 DAG)

  • fee – Integer with 8 decimals (e.g. 20000 = 0.0002 DAG)

  • auto_estimate_fee

Returns:

async transfer_batch(transfers: List[dict], last_ref: dict | TransactionReference | None = None)[source]

Build and send $DAG currency transactions.

Parameters:
  • transfers – List of dictionaries, e.g. txn_data = [ {‘to_address’: to_address, ‘amount’: 10000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 5000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 2500000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 1, ‘fee’: 200000} ]

  • last_ref – Dictionary with former ordinal and transaction hash, e.g.: {‘ordinal’: x, ‘hash’: y}.

Returns:

async transfer_batch_transactions(transactions: List[SignedTransaction])[source]

Send a batch (list) of signed currency transactions.

Parameters:

transactions – [SignedTransaction, … ]

Returns:

List of transaction hashes.

async wait(time: float = 5.0)[source]
async wait_for_balance_change(initial_value: int | None = None)[source]

Check if balance changed since initial value.

Parameters:

initial_value

Returns:

True if balance changed, False if no change.

async wait_for_checkpoint_accepted(hash: str)[source]

Check if transaction has been processed.

Parameters:

hash – Transaction hash.

Returns:

True if processed, False if not processed.

async withdraw_delegate_stake()[source]
pypergraph.DagMonitor

alias of Monitor

class pypergraph.DagTokenNetwork(network_id: str = 'mainnet', l0_host: str | None = None, currency_l1_host: str | None = None, client: RESTClient | None = None)[source]

Bases: object

config(network_id: str = None, block_explorer_url: str | None = None, l0_host: str | None = None, currency_l1_host: str | None = None)[source]

Reconfigure the network; new configuration is applied only if different from the current one.

async get_address_balance(address: str) Balance[source]
async get_address_last_accepted_transaction_ref(address: str) TransactionReference[source]

Get the last transaction hash and ordinal from DAG address.

Parameters:

address

Returns:

Object with ordinal and transaction hash.

async get_latest_snapshot() Snapshot[source]

Get the latest snapshot from the block explorer.

Returns:

Snapshot object.

get_network() Dict[source]

Returns the DagTokenNetwork NetworkInfo object as dictionary.

Returns:

Serialized NetworkInfo object.

async get_pending_transaction(hash: str) PendingTransaction[source]

Check if the given transaction is pending.

Parameters:

hash

Returns:

Object if transaction is pending, else log error.

async get_transaction(hash: str) Transaction[source]

Get the given transaction from the block explorer.

Parameters:

hash – Transaction hash.

Returns:

BlockExplorerTransaction object.

async get_transactions_by_address(address: str, limit: int | None = None, search_after: str | None = None) List[Transaction][source]

Get all address-specific transactions from a given timestamp.

Parameters:
  • address – DAG address.

  • limit – Limit per page.

  • search_after – Timestamp.

Returns:

List of BlockExplorerTransaction objects.

async post_delegate_stake(tx: dict) str[source]

Delegate stake on L0. I believe this is a one-time thing for node operators to make the node available for delegated stake?

Parameters:

tx – Signed transaction.

Returns:

Transaction hash.

async post_transaction(tx: SignedTransaction) str[source]

Post a signed transaction to layer 1.

Parameters:

tx – Signed transaction.

Returns:

Transaction hash.

set_network(network_info: NetworkInfo)[source]
class pypergraph.KeyStore[source]

Bases: object

Methods dealing with keys.

DATA_SIGN_PREFIX = '\x19Constellation Signed Data:\n'
PERSONAL_SIGN_PREFIX = '\x19Constellation Signed Message:\n'
brotli_sign(public_key: str, private_key: str, body: dict)[source]
data_sign(private_key, msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) Tuple[str, str][source]

Encode message according to serializeUpdate on your template module l1.

param private_key:

param msg:

Dictionary (the content of ‘value’ in a SignedTransaction).

param prefix:

Enable or disable the default prefix ‘Constellation Signed Data:

‘ to the encoded msg or inject custom string.
param encoding:

Can be None (default), ‘base64’ or a custom encoding function.

return:

signature, transaction hash.

async static decrypt_phrase(keystore: V3Keystore, password: str) str[source]

Can be used to decrypt the phrase using password.

Parameters:
  • keystore

  • password

Returns:

decrypt_private_key(data: dict, password: str)[source]
static derive_account_from_master_key(master_key: BIP32Key, index: int) str[source]

Derive HD private key from master key.

Parameters:
  • master_key

  • index

Returns:

encode_data(msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) str[source]

Encode custom data transaction for signing or signature verification.

param msg:

Dictionary (the content of ‘value’ in a SignedTransaction).

param prefix:

Enable or disable the default prefix ‘Constellation Signed Data:

‘ to the encoded msg.
param encoding:

Can be None (default), ‘base64’ or a custom encoding function.

return:

Encoded data transaction.

async static encrypt_phrase(phrase: str, password: str) V3Keystore[source]

Can be used to encrypt the phrase using password.

Parameters:
  • phrase

  • password

Returns:

encrypt_private_key(password: str, private_key: str | None = None) Dict[str, Any][source]

Can be stored (written to disk) and transferred.

Parameters:
  • private_key

  • password

Returns:

Dictionary, use json.dumps()

static generate_mnemonic() str[source]
Returns:

12 word mnemonic phrase

generate_private_key() str[source]

Generates private key.

Returns:

Private key hex.

get_dag_address_from_private_key(private_key: str)[source]
static get_dag_address_from_public_key(public_key: str) str[source]
Parameters:

public_key – The private key as a hexadecimal string.

Returns:

The DAG address corresponding to the public key (node ID).

get_eth_address_from_private_key(private_key: str) str[source]
static get_eth_address_from_public_key(public_key: str) str[source]
static get_extended_private_key_from_mnemonic(phrase: str)[source]
static get_master_key_from_mnemonic(phrase: str, derivation_path: str = "m/44'/1137'/0'/0")[source]

Master key can be used to derive HD keys.

Parameters:
  • phrase

  • derivation_path

Returns:

static get_private_key_from_mnemonic(phrase: str, derivation_path="m/44'/1137'/0'/0") str[source]

Get private key from phrase. Returns the first account.

Parameters:
  • phrase

  • derivation_path

Returns:

Private key as hexadecimal string

static get_public_key_from_private(private_key: str) str[source]
Parameters:

private_key

Returns:

Public key (Node ID)

personal_sign(msg, private_key) str[source]
static prepare_tx(amount: int, to_address: str, from_address: str, last_ref: TransactionReference, fee: int = 0) Tuple[Transaction, str][source]

Prepare a new transaction.

Parameters:
  • amount – Amount to send.

  • to_address – Destination DAG address.

  • from_address – Source DAG address.

  • last_ref – Dictionary with keys: ordinal, hash.

  • fee – Transaction fee.

Returns:

TransactionV2 object, sha512hash, rle.

static sign(private_key: str, msg: str) str[source]

Create transaction signature using the cryptography library.

Parameters:
  • private_key – Private key in hex format.

  • msg – Transaction message (string).

Returns:

Canonical DER signature in hex.

static validate_address(address: str) bool[source]

Returns True if DAG address is valid, False if invalid.

Parameters:

address – DAG address.

Returns:

Boolean value.

static validate_mnemonic(phrase: str) bool[source]

Returns True is phrase is valid, False if invalid.

Parameters:

phrase – String of words (default: 12).

Returns:

Boolean value.

static validate_private_key_keystore(data: dict) bool[source]
static verify(public_key: str, msg: str, signature: str) bool[source]

Verify is the signature is valid.

Parameters:
  • public_key

  • msg – Hex format

  • signature

Returns:

True or False

verify_data(public_key: str, encoded_msg: str, signature: str)[source]

Verify a signature using the cryptography library.

Parameters:
  • public_key – Public key in hex format (64-byte uncompressed, no 0x04 prefix).

  • encoded_msg – Original message string to verify.

  • signature – Canonical DER signature in hex.

Returns:

True if valid, False otherwise.

class pypergraph.KeyringManager(storage_file_path: str | None = None)[source]

Bases: object

check_password(password) bool[source]
async clear_wallets()[source]

Clear wallet cache.

async create_multi_chain_hd_wallet(label: str | None = None, seed: str | None = None) MultiChainWallet[source]

This is the next step in creating or restoring a wallet, by default.

Parameters:
  • label – Wallet name.

  • seed – Seed phrase.

Returns:

async create_or_restore_vault(password: str, label: str | None = None, seed: str | None = None) MultiChainWallet[source]

First step, creating or restoring a wallet. This is the default wallet type when creating a new wallet.

Parameters:
  • label – The name of the wallet.

  • seed – Seed phrase.

  • password – A string of characters.

Returns:

async create_single_account_wallet(label: str, private_key: str, network: Constellation | Ethereum | None = None) SingleAccountWallet[source]
static generate_mnemonic() str[source]
get_accounts() List[DagAccount | EthAccount][source]
get_wallet_by_id(id: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
get_wallet_for_account(address: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
is_unlocked() bool[source]
async login(password: str)[source]
async logout()[source]
async remove_account(address)[source]
remove_empty_wallets()[source]
set_password(password: str)[source]

Will enforce basic restrictions on password creation

set_wallet_label(wallet_id: str, label: str)[source]
class pypergraph.MetagraphTokenClient(account: DagAccount, metagraph_id: str, block_explorer_url: str | None = None, l0_host: str | None = None, currency_l1_host: str | None = None, data_l1_host: str | None = None, token_decimals: int = 8)[source]

Bases: object

Create a metagraph account from DagAccount.

class DagAccount

Bases: object

property address

Requires login. Get the DagAccount DAG address. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

Returns:

DAG address.

connect(network_id: str | None = 'mainnet', be_url: str | None = None, l0_host: str | None = None, cl1_host: str | None = None) DagAccount

Configure the DagAccount network instance. Parameter ‘network_id’ can be used to change between ‘testnet’, ‘integrationnet’ or ‘mainnet’, without further parameter settings. Default: ‘mainnet’.

Parameters:
  • network_id – ‘mainnet’, ‘integrationnet’, ‘testnet’ or any string value.

  • be_url – Block Explorer host URL.

  • l0_host – Layer 0 host URL.

  • cl1_host – Currency Layer 1 host URL.

Returns:

Configured DagAccount object.

async create_allow_spend(destination: str, amount: int, approvers: List[str], source: str | None = None, fee: int = 0, currency_id: str | None = None, valid_until_epoch: int | None = None)

Grants permission for another wallet or metagraph to spend up to a specified amount from the user’s wallet in a metagraph token or DAG.

Parameters:
  • source – Wallet address signing the transaction. Address of logged in account, if left None

  • destination – The destination address. This must be a Metagraph address.

  • amount – The amount the destination address is allowed to spend.

  • approvers – A list with single DAG address that can automatically approve the spend, can be Metagraph or wallet address.

  • currency_id – The Metagraph ID used to identify the currency. For DAG, this parameter is left None.

  • fee – Default 0.

  • valid_until_epoch – The global snapshot epoch progress for which this is valid until. If not provided, the default value will be currentEpoch + 30. Minumum allowed value: currentEpoch + 5. Maximum allowed value: currentEpoch + 60.

async create_delegate_stake()
create_metagraph_token_client(account: Self | None = None, metagraph_id: str | None = None, block_explorer_url: str | None = None, l0_host: str | None = None, currency_l1_host: str | None = None, data_l1_host: str | None = None, token_decimals: int = 8)

Derive a Metagraph client from the active account to interact with a Metagraph.

Parameters:
  • account – active DagAccount.

  • metagraph_id – Associated Metagraph $DAG address.

  • block_explorer_url – (Optional) Block Explorer URL (default: associated account).

  • l0_host – (Optional) Layer 0 host URL (port might be required).

  • cl1_host – (Optional) Layer 1 currency host URL (port might be required).

  • dl1_host – (Optional) Layer 1 data host URL (port might be required).

  • token_decimals – (Optional) 1 $DAG = 100000000 (default: 8)

Returns:

Metagraph token client object.

async create_token_lock(amount: int, fee: int = 0, unlock_epoch: int = None, source: str | None = None, currency_id: str | None = None)

Token locking is used for:

Node collateral staking Delegated staking participation Governance requirements Time-based vesting or escrow models

Parameters:
  • source – The wallet signing the transaction. The logged in account is the default if left empty.

  • amount – The amount to lock.

  • currency_id – The Metagraph identifier address for the currency to lock. Leave None, if currency is DAG.

  • fee – The fee. Default when None is 0.

  • unlock_epoch – The global snapshot epoch progress to unlock the tokens. If provided, must be greater than the current epoch.

async generate_batch_transactions(transfers: List[dict], last_ref: dict | TransactionReference | None = None)

Generate a batch of transactions to be transferred from the active account.

Parameters:
  • transfers – List of dictionaries, e.g. txn_data = [ {‘to_address’: to_address, ‘amount’: 10000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 5000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 2500000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 1, ‘fee’: 200000} ]

  • last_ref – (Optional) Dictionary or with the account’s last transaction hash and ordinal.

Returns:

List of transactions to be transferred (see: transfer_batch_transactions(transactions=))

async generate_signed_transaction(to_address: str, amount: int, fee: int = 0, last_ref: dict | TransactionReference | None = None) Tuple[SignedTransaction, str]

Generate a signed currency transaction from the currently active account.

Parameters:
  • to_address – Recipient DAG address.

  • amount – Integer with 8 decimals constituting the amount to transfer from the active account.

  • fee – (Optional) a minimum fee might be required if the active account is transaction limited.

  • last_ref – (Optional) The ordinal and hash of the last transaction from the active account.

Returns:

Signed transaction and the transaction hash.

async get_balance()

Get the balance for the active account.

Returns:

async get_balance_for(address: str)

Get balance for a given DAG address. Returned as integer with 8 decimals.

Parameters:

address – DAG address.

Returns:

0 or 8 decimal integer.

get_eth_address() str
is_active()

Check if any account is logged in.

Returns:

login_with_private_key(private_key: str)

Login with a private key. Before transferring data or currency you need to login using a seed phrase or private key.

Parameters:

private_key – Private key.

Returns:

login_with_public_key(public_key: str)

Login with public key. This method does not enable the account to transfer data or currency. See: login_with_seed_phrase(words=) or login_with_private_key(private_key=)

Parameters:

public_key

Returns:

login_with_seed_phrase(phrase: str)

Login with a 12 word seed phrase. Before transferring data or currency you need to login using a seed phrase or private key.

Parameters:

phrase – 12 word seed phrase.

Returns:

logout()

Logout the active account (delete key trio).

Returns:

property private_key

Requires login. Get the DagAccount private key. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

Returns:

Private key.

property public_key

Requires login. Get the DagAccount public key. See: login_with_seed_phrase(words=), login_with_private_key(private_key=) and login_with_public_key(public_key=)

This method does not support transfer of data or currency, due to missing private key.

Returns:

Public key.

async set_node_parameters()
async transfer(to_address: str, amount: int, fee: int = 0, auto_estimate_fee=False) PendingTransaction | None

Build currency transaction, sign and transfer from the active account.

Parameters:
  • to_address – DAG address

  • amount – Integer with 8 decimals (e.g. 100000000 = 1 DAG)

  • fee – Integer with 8 decimals (e.g. 20000 = 0.0002 DAG)

  • auto_estimate_fee

Returns:

async transfer_batch(transfers: List[dict], last_ref: dict | TransactionReference | None = None)

Build and send $DAG currency transactions.

Parameters:
  • transfers – List of dictionaries, e.g. txn_data = [ {‘to_address’: to_address, ‘amount’: 10000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 5000000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 2500000, ‘fee’: 200000}, {‘to_address’: to_address, ‘amount’: 1, ‘fee’: 200000} ]

  • last_ref – Dictionary with former ordinal and transaction hash, e.g.: {‘ordinal’: x, ‘hash’: y}.

Returns:

async transfer_batch_transactions(transactions: List[SignedTransaction])

Send a batch (list) of signed currency transactions.

Parameters:

transactions – [SignedTransaction, … ]

Returns:

List of transaction hashes.

async wait(time: float = 5.0)
async wait_for_balance_change(initial_value: int | None = None)

Check if balance changed since initial value.

Parameters:

initial_value

Returns:

True if balance changed, False if no change.

async wait_for_checkpoint_accepted(hash: str)

Check if transaction has been processed.

Parameters:

hash – Transaction hash.

Returns:

True if processed, False if not processed.

async withdraw_delegate_stake()
property address
async create_allow_spend(destination: str, amount: int, approvers: List[str], source: str | None = None, fee: int = 0, currency_id: str | None = None, valid_until_epoch: int | None = None)[source]

Grants permission for another wallet or metagraph to spend up to a specified amount from the user’s wallet in a metagraph token or DAG.

Parameters:
  • source – Wallet address signing the transaction. Address of logged in account, if left None

  • destination – The destination address. This must be a Metagraph address.

  • amount – The amount the destination address is allowed to spend.

  • approvers – A list with single DAG address that can automatically approve the spend, can be Metagraph or wallet address.

  • currency_id – The Metagraph ID used to identify the currency. For DAG, this parameter is left None.

  • fee – Default 0.

  • valid_until_epoch – The global snapshot epoch progress for which this is valid until. If not provided, the default value will be currentEpoch + 30. Minumum allowed value: currentEpoch + 5. Maximum allowed value: currentEpoch + 60.

async create_token_lock(amount: int, fee: int = 0, unlock_epoch: int = None, source: str = None, currency_id: str | None = None)[source]

Token locking is used for:

Node collateral staking Delegated staking participation Governance requirements Time-based vesting or escrow models

Parameters:
  • source – The wallet signing the transaction. The logged in account is the default if left empty.

  • amount – The amount to lock.

  • currency_id – The Metagraph identifier address for the currency to lock. Leave None, if currency is DAG.

  • fee – The fee. Default when None is 0.

  • unlock_epoch – The global snapshot epoch progress to unlock the tokens. If provided, must be greater than the current epoch.

async generate_batch_transactions(transfers: List[Dict[str, Any]], last_ref: Dict[str, Any] | TransactionReference | None = None)[source]

Takes a list of dictionaries and returns a list of signed transaction objects.

Parameters:
  • transfers – List of dictionaries.

  • last_ref – Lost hash and ordinal from DAG address.

Returns:

async get_balance() int[source]

Get Metagraph token balance for the active account.

Returns:

Integer.

async get_balance_for(address: str) int[source]

Get Metagraph token balance for the active account.

Returns:

Integer.

async get_fee_recommendation()[source]
async get_transactions(limit: int | None = None, search_after: str | None = None)[source]

Get paginated list of Block Explorer transaction objects.

Parameters:
  • limit – Limit per page.

  • search_after – Timestamp.

Returns:

property network_instance
async transfer(to_address: str, amount: int, fee: int = 0, auto_estimate_fee: bool = False) Dict[str, Any] | None[source]

Transfer DAG from active account to another DAG address. Amount as integer with the number of decimals used by the Metagraph.

Parameters:
  • to_address – DAG address.

  • amount – Integer with the number of decimals used by the Metagraph.

  • fee – Integer with the number of decimals used by the Metagraph.

  • auto_estimate_fee

Returns:

Dictionary.

async transfer_batch(transfers: List[Dict[str, Any]], last_ref: Dict[str, Any] | TransactionReference | None = None)[source]

Build and send a list of transactions from the active account.

Parameters:
  • transfers – List of dictionaries.

  • last_ref – Last ordinal and hash from active account.

Returns:

List of transaction hashes.

async transfer_batch_transactions(transactions: List[SignedTransaction]) List[str | None][source]

Send a list of signed transaction objects from the active account.

Parameters:

transactions – List of signed transactions.

Returns:

List of transactions.

async wait(time_in_seconds: int = 5)[source]

Wait for a number of seconds.

Parameters:

time_in_seconds – Integer.

async wait_for_balance_change(initial_value: int | None = None)[source]

Check if active account balance changes (around 2 minutes).

Parameters:

initial_value

Returns:

False if check did not detect balance change, else True.

class pypergraph.MetagraphTokenNetwork(metagraph_id: str, l0_host: str | None = None, currency_l1_host: str | None = None, data_l1_host: str | None = None, network_id: str | None = 'mainnet', block_explorer: str | None = None, client: RESTClient | None = None)[source]

Bases: object

Network instance used to interact with Constellation Network layer 0 and Metagraph currency and data layers. Can be used as a separate instance or as ‘network’ in MetagraphTokenClient.

async get_address_balance(address: str) Balance[source]

Get the current balance of a given DAG address.

Parameters:

address – DAG address.

Returns:

Balance object.

async get_address_last_accepted_transaction_ref(address: str) TransactionReference[source]

Get the last transaction hash and ordinal from a DAG address.

Parameters:

address – DAG address.

Returns:

Object with ordinal and hash.

async get_data()[source]

NOT IMPLEMENTED YET! Get data from Metagraph data layer 1.

Returns:

Data extracted from the response or None.

async get_latest_snapshot()[source]

Get the latest snapshot from Metagraph.

Returns:

A snapshot (type currency).

get_network() Dict[source]

Returns the MetagraphTokenNetwork NetworkInfo object as a dictionary.

Returns:

Serialized NetworkInfo object.

async get_pending_transaction(hash: str | None) PendingTransaction | None[source]

Check if the given transaction is pending.

Parameters:

hash – The transaction hash.

Returns:

PendingTransaction object if found; otherwise, None.

async get_transaction(hash: str | None) Transaction | None[source]

Get the given transaction.

Parameters:

hash – Transaction hash.

Returns:

BlockExplorerTransaction object or None.

async get_transactions_by_address(address: str, limit: int | None = None, search_after: str | None = None) List[Transaction] | None[source]

Get a paginated list of Block Explorer transaction objects.

Parameters:
  • address – DAG address.

  • limit – Limit per page.

  • search_after – Timestamp to paginate.

Returns:

List of BlockExplorerTransaction objects or None.

async post_data(tx: Dict[str, Dict]) dict[source]

Post data to Metagraph. Signed transaction should be in the format:

{

“value”: { … }, “proofs”: [

{

“id”: “c7f9a08bdea7ff5f51c8af16e223a1d751bac9c541125d9aef5658e9b7597aee8cba374119ebe83fb9edd8c0b4654af273f2d052e2d7dd5c6160b6d6c284a17c”, “signature”: “3045022017607e6f32295b0ba73b372e31780bd373322b6342c3d234b77bea46adc78dde022100e6ffe2bca011f4850b7c76d549f6768b88d0f4c09745c6567bbbe45983a28bf1”

}

]

}

Parameters:

tx – Signed transaction as a dictionary.

Returns:

Dictionary with response from Metagraph.

async post_transaction(tx: SignedTransaction) str | None[source]

Post a signed transaction to Metagraph.

Parameters:

tx – Signed transaction.

Returns:

Transaction hash.