pypergraph package¶
Subpackages¶
- pypergraph.account package
- Submodules
- pypergraph.account.dag_account module
DagAccountDagAccount.addressDagAccount.connect()DagAccount.create_allow_spend()DagAccount.create_delegate_stake()DagAccount.create_metagraph_token_client()DagAccount.create_token_lock()DagAccount.generate_batch_transactions()DagAccount.generate_signed_transaction()DagAccount.get_balance()DagAccount.get_balance_for()DagAccount.get_eth_address()DagAccount.is_active()DagAccount.login_with_private_key()DagAccount.login_with_public_key()DagAccount.login_with_seed_phrase()DagAccount.logout()DagAccount.private_keyDagAccount.public_keyDagAccount.set_node_parameters()DagAccount.transfer()DagAccount.transfer_batch()DagAccount.transfer_batch_transactions()DagAccount.wait()DagAccount.wait_for_balance_change()DagAccount.wait_for_checkpoint_accepted()DagAccount.withdraw_delegate_stake()
- pypergraph.account.metagraph_client module
MetagraphTokenClientMetagraphTokenClient.DagAccountMetagraphTokenClient.addressMetagraphTokenClient.create_allow_spend()MetagraphTokenClient.create_token_lock()MetagraphTokenClient.generate_batch_transactions()MetagraphTokenClient.get_balance()MetagraphTokenClient.get_balance_for()MetagraphTokenClient.get_fee_recommendation()MetagraphTokenClient.get_transactions()MetagraphTokenClient.network_instanceMetagraphTokenClient.transfer()MetagraphTokenClient.transfer_batch()MetagraphTokenClient.transfer_batch_transactions()MetagraphTokenClient.wait()MetagraphTokenClient.wait_for_balance_change()
- pypergraph.account.monitor module
DagWalletMonitorUpdateMonitorMonitor.add_to_mem_pool_monitor()Monitor.get_latest_transactions()Monitor.get_mem_pool_from_monitor()Monitor.poll_pending_txs()Monitor.process_pending_txs()Monitor.set_to_mem_pool_monitor()Monitor.start_monitor()Monitor.subscribe_account()Monitor.subscribe_mem_pool()Monitor.subscribe_network()
main()
- Module contents
DagAccountDagAccount.addressDagAccount.connect()DagAccount.create_allow_spend()DagAccount.create_delegate_stake()DagAccount.create_metagraph_token_client()DagAccount.create_token_lock()DagAccount.generate_batch_transactions()DagAccount.generate_signed_transaction()DagAccount.get_balance()DagAccount.get_balance_for()DagAccount.get_eth_address()DagAccount.is_active()DagAccount.login_with_private_key()DagAccount.login_with_public_key()DagAccount.login_with_seed_phrase()DagAccount.logout()DagAccount.private_keyDagAccount.public_keyDagAccount.set_node_parameters()DagAccount.transfer()DagAccount.transfer_batch()DagAccount.transfer_batch_transactions()DagAccount.wait()DagAccount.wait_for_balance_change()DagAccount.wait_for_checkpoint_accepted()DagAccount.withdraw_delegate_stake()
DagMonitorMetagraphTokenClientMetagraphTokenClient.DagAccountMetagraphTokenClient.addressMetagraphTokenClient.create_allow_spend()MetagraphTokenClient.create_token_lock()MetagraphTokenClient.generate_batch_transactions()MetagraphTokenClient.get_balance()MetagraphTokenClient.get_balance_for()MetagraphTokenClient.get_fee_recommendation()MetagraphTokenClient.get_transactions()MetagraphTokenClient.network_instanceMetagraphTokenClient.transfer()MetagraphTokenClient.transfer_batch()MetagraphTokenClient.transfer_batch_transactions()MetagraphTokenClient.wait()MetagraphTokenClient.wait_for_balance_change()
- pypergraph.core package
- pypergraph.keyring package
- Subpackages
- Submodules
- pypergraph.keyring.encryptor module
- pypergraph.keyring.manager module
KeyringManagerKeyringManager.check_password()KeyringManager.clear_wallets()KeyringManager.create_multi_chain_hd_wallet()KeyringManager.create_or_restore_vault()KeyringManager.create_single_account_wallet()KeyringManager.generate_mnemonic()KeyringManager.get_accounts()KeyringManager.get_wallet_by_id()KeyringManager.get_wallet_for_account()KeyringManager.is_unlocked()KeyringManager.login()KeyringManager.logout()KeyringManager.remove_account()KeyringManager.remove_empty_wallets()KeyringManager.set_password()KeyringManager.set_wallet_label()
- Module contents
EncryptorHdKeyringHdKeyring.accountsHdKeyring.add_account_at()HdKeyring.create()HdKeyring.create_accounts()HdKeyring.create_from_extended_key()HdKeyring.deserialize()HdKeyring.export_account()HdKeyring.extended_keyHdKeyring.get_account_by_address()HdKeyring.get_accounts()HdKeyring.get_extended_public_key()HdKeyring.get_hd_path()HdKeyring.get_network()HdKeyring.hd_pathHdKeyring.mnemonicHdKeyring.model_configHdKeyring.model_serialize()HdKeyring.networkHdKeyring.remove_account()HdKeyring.remove_last_added_account()HdKeyring.root_key
KeyringAssetInfoKeyringManagerKeyringManager.check_password()KeyringManager.clear_wallets()KeyringManager.create_multi_chain_hd_wallet()KeyringManager.create_or_restore_vault()KeyringManager.create_single_account_wallet()KeyringManager.generate_mnemonic()KeyringManager.get_accounts()KeyringManager.get_wallet_by_id()KeyringManager.get_wallet_for_account()KeyringManager.is_unlocked()KeyringManager.login()KeyringManager.logout()KeyringManager.remove_account()KeyringManager.remove_empty_wallets()KeyringManager.set_password()KeyringManager.set_wallet_label()
MultiAccountWalletMultiAccountWallet.add_account()MultiAccountWallet.compute_id()MultiAccountWallet.create()MultiAccountWallet.deserialize()MultiAccountWallet.export_secret_key()MultiAccountWallet.get_account_by_address()MultiAccountWallet.get_accounts()MultiAccountWallet.get_label()MultiAccountWallet.get_network()MultiAccountWallet.get_state()MultiAccountWallet.idMultiAccountWallet.import_account()MultiAccountWallet.keyringMultiAccountWallet.labelMultiAccountWallet.mnemonicMultiAccountWallet.model_configMultiAccountWallet.model_serialize()MultiAccountWallet.networkMultiAccountWallet.remove_account()MultiAccountWallet.reset_sid()MultiAccountWallet.set_label()MultiAccountWallet.set_num_of_accounts()MultiAccountWallet.supported_assetsMultiAccountWallet.type
MultiChainWalletMultiChainWallet.compute_id()MultiChainWallet.create()MultiChainWallet.deserialize()MultiChainWallet.export_secret_key()MultiChainWallet.get_account_by_address()MultiChainWallet.get_accounts()MultiChainWallet.get_label()MultiChainWallet.get_network()MultiChainWallet.get_state()MultiChainWallet.idMultiChainWallet.import_account()MultiChainWallet.keyringsMultiChainWallet.labelMultiChainWallet.mnemonicMultiChainWallet.model_configMultiChainWallet.model_serialize()MultiChainWallet.remove_account()MultiChainWallet.reset_sid()MultiChainWallet.set_label()MultiChainWallet.supported_assetsMultiChainWallet.type
MultiKeyWalletMultiKeyWallet.compute_id()MultiKeyWallet.create()MultiKeyWallet.deserialize()MultiKeyWallet.export_secret_key()MultiKeyWallet.get_account_by_address()MultiKeyWallet.get_accounts()MultiKeyWallet.get_label()MultiKeyWallet.get_network()MultiKeyWallet.get_state()MultiKeyWallet.idMultiKeyWallet.import_account()MultiKeyWallet.keyringsMultiKeyWallet.labelMultiKeyWallet.model_configMultiKeyWallet.model_serialize()MultiKeyWallet.networkMultiKeyWallet.remove_account()MultiKeyWallet.reset_sid()MultiKeyWallet.set_label()MultiKeyWallet.supported_assetsMultiKeyWallet.type
SimpleKeyringSimpleKeyring.accountSimpleKeyring.add_account_at()SimpleKeyring.create_for_network()SimpleKeyring.deserialize()SimpleKeyring.get_account_by_address()SimpleKeyring.get_accounts()SimpleKeyring.get_state()SimpleKeyring.model_configSimpleKeyring.model_serialize()SimpleKeyring.networkSimpleKeyring.remove_account()
SingleAccountWalletSingleAccountWallet.compute_id()SingleAccountWallet.create()SingleAccountWallet.deserialize()SingleAccountWallet.export_secret_key()SingleAccountWallet.get_account_by_address()SingleAccountWallet.get_accounts()SingleAccountWallet.get_label()SingleAccountWallet.get_network()SingleAccountWallet.get_state()SingleAccountWallet.idSingleAccountWallet.import_account()SingleAccountWallet.keyringSingleAccountWallet.labelSingleAccountWallet.model_configSingleAccountWallet.model_serialize()SingleAccountWallet.networkSingleAccountWallet.remove_account()SingleAccountWallet.reset_sid()SingleAccountWallet.set_label()SingleAccountWallet.supported_assetsSingleAccountWallet.type
- pypergraph.keystore package
- Subpackages
- Submodules
- pypergraph.keystore.keystore module
KeyStoreKeyStore.DATA_SIGN_PREFIXKeyStore.PERSONAL_SIGN_PREFIXKeyStore.brotli_sign()KeyStore.data_sign()KeyStore.decrypt_phrase()KeyStore.decrypt_private_key()KeyStore.derive_account_from_master_key()KeyStore.encode_data()KeyStore.encrypt_phrase()KeyStore.encrypt_private_key()KeyStore.generate_mnemonic()KeyStore.generate_private_key()KeyStore.get_dag_address_from_private_key()KeyStore.get_dag_address_from_public_key()KeyStore.get_eth_address_from_private_key()KeyStore.get_eth_address_from_public_key()KeyStore.get_extended_private_key_from_mnemonic()KeyStore.get_master_key_from_mnemonic()KeyStore.get_private_key_from_mnemonic()KeyStore.get_public_key_from_private()KeyStore.personal_sign()KeyStore.prepare_tx()KeyStore.sign()KeyStore.validate_address()KeyStore.validate_mnemonic()KeyStore.validate_private_key_keystore()KeyStore.verify()KeyStore.verify_data()
- pypergraph.keystore.kryo module
- pypergraph.keystore.v3_keystore module
- Module contents
KeyStoreKeyStore.DATA_SIGN_PREFIXKeyStore.PERSONAL_SIGN_PREFIXKeyStore.brotli_sign()KeyStore.data_sign()KeyStore.decrypt_phrase()KeyStore.decrypt_private_key()KeyStore.derive_account_from_master_key()KeyStore.encode_data()KeyStore.encrypt_phrase()KeyStore.encrypt_private_key()KeyStore.generate_mnemonic()KeyStore.generate_private_key()KeyStore.get_dag_address_from_private_key()KeyStore.get_dag_address_from_public_key()KeyStore.get_eth_address_from_private_key()KeyStore.get_eth_address_from_public_key()KeyStore.get_extended_private_key_from_mnemonic()KeyStore.get_master_key_from_mnemonic()KeyStore.get_private_key_from_mnemonic()KeyStore.get_public_key_from_private()KeyStore.personal_sign()KeyStore.prepare_tx()KeyStore.sign()KeyStore.validate_address()KeyStore.validate_mnemonic()KeyStore.validate_private_key_keystore()KeyStore.verify()KeyStore.verify_data()
- pypergraph.network package
- Subpackages
- pypergraph.network.api package
- Submodules
- pypergraph.network.api.block_explorer_api module
- pypergraph.network.api.layer_0_api module
- pypergraph.network.api.layer_1_api module
- pypergraph.network.api.metagraph_currency_layer_1_api module
- pypergraph.network.api.metagraph_data_layer_1_api module
- pypergraph.network.api.metagraph_layer_0_api module
- Module contents
- pypergraph.network.models package
- pypergraph.network.tests package
- pypergraph.network.api package
- Submodules
- pypergraph.network.dag_network module
DagTokenNetworkDagTokenNetwork.config()DagTokenNetwork.get_address_balance()DagTokenNetwork.get_address_last_accepted_transaction_ref()DagTokenNetwork.get_latest_snapshot()DagTokenNetwork.get_network()DagTokenNetwork.get_pending_transaction()DagTokenNetwork.get_transaction()DagTokenNetwork.get_transactions_by_address()DagTokenNetwork.post_delegate_stake()DagTokenNetwork.post_transaction()DagTokenNetwork.set_network()
- pypergraph.network.metagraph_network module
MetagraphTokenNetworkMetagraphTokenNetwork.get_address_balance()MetagraphTokenNetwork.get_address_last_accepted_transaction_ref()MetagraphTokenNetwork.get_data()MetagraphTokenNetwork.get_latest_snapshot()MetagraphTokenNetwork.get_network()MetagraphTokenNetwork.get_pending_transaction()MetagraphTokenNetwork.get_transaction()MetagraphTokenNetwork.get_transactions_by_address()MetagraphTokenNetwork.post_data()MetagraphTokenNetwork.post_transaction()
- Module contents
DagTokenNetworkDagTokenNetwork.config()DagTokenNetwork.get_address_balance()DagTokenNetwork.get_address_last_accepted_transaction_ref()DagTokenNetwork.get_latest_snapshot()DagTokenNetwork.get_network()DagTokenNetwork.get_pending_transaction()DagTokenNetwork.get_transaction()DagTokenNetwork.get_transactions_by_address()DagTokenNetwork.post_delegate_stake()DagTokenNetwork.post_transaction()DagTokenNetwork.set_network()
MetagraphTokenNetworkMetagraphTokenNetwork.get_address_balance()MetagraphTokenNetwork.get_address_last_accepted_transaction_ref()MetagraphTokenNetwork.get_data()MetagraphTokenNetwork.get_latest_snapshot()MetagraphTokenNetwork.get_network()MetagraphTokenNetwork.get_pending_transaction()MetagraphTokenNetwork.get_transaction()MetagraphTokenNetwork.get_transactions_by_address()MetagraphTokenNetwork.post_data()MetagraphTokenNetwork.post_transaction()
- 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.
- 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_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.
- 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:
- 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 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_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.
- 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_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:
objectMethods dealing with keys.
- DATA_SIGN_PREFIX = '\x19Constellation Signed Data:\n'¶
- PERSONAL_SIGN_PREFIX = '\x19Constellation Signed Message:\n'¶
- 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:
- 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 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).
- 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)
- 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 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- 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]¶
- 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]¶
- 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:
objectCreate 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_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.
- 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:
objectNetwork 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.