pypergraph.account package

Submodules

pypergraph.account.dag_account module

class pypergraph.account.dag_account.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.account.metagraph_client module

class pypergraph.account.metagraph_client.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.

pypergraph.account.monitor module

class pypergraph.account.monitor.DagWalletMonitorUpdate(*, pending_has_confirmed: bool = False, trans_txs: ~typing.List[~pypergraph.network.models.transaction.PendingTransaction] = <factory>, tx_changed: bool = False)[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pending_has_confirmed: bool
trans_txs: List[PendingTransaction]
tx_changed: bool
class pypergraph.account.monitor.Monitor(account, state_storage_file_path: str)[source]

Bases: object

async add_to_mem_pool_monitor(value: PendingTransaction)[source]
async get_latest_transactions(address: str, limit: int | None = None, search_after: str | None = None) List[PendingTransaction | Transaction][source]
async get_mem_pool_from_monitor(address: str | None = None) List[PendingTransaction][source]
async poll_pending_txs()[source]
async process_pending_txs() Dict[str, Any][source]
async set_to_mem_pool_monitor(pool: List[PendingTransaction])[source]
start_monitor()[source]
subscribe_account(callback: Callable[[Any], Observable]) Disposable[source]

Listen for account events like login and logout. Event = {“module”: “account”, “event”: “logout”}

subscribe_mem_pool(callback: Callable[[Any], Observable]) Disposable[source]

Listen for account events like login and logout. Event = {“module”: “account”, “event”: “logout”}

subscribe_network(callback: Callable[[Any], Observable]) Disposable[source]

Listen for network events like network_change. Event = {

“module”: “network”, “type”: “network_change”, “event”: self.get_network(),

}

async pypergraph.account.monitor.main()[source]

Module contents

class pypergraph.account.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.account.DagMonitor

alias of Monitor

class pypergraph.account.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.