AlgoUtils

class gridworks.algo_utils.BasicAccount(private_key=None)

Representation of the public and private information of an Algorand account, with a few shorthands on top of algosdk.account - in particular x = BasicAccount() will generate a new BasicAccount.

Parameters:

private_key (str | None) –

property addr: str

Shorthand property for the account’s public key

property addr_short_hand: str

Returns the last 6 characters of the account address. Used for logging messages and human eyes.

address()

A method returning the account’s public key. Equivalent to self.addr

Return type:

str

property address_as_bytes: bytes

Useful if digging into encoding and decoding between strings and bytes.

classmethod from_mnemonic(m)

Takes the string of 25 words (the mnemonic) and returns the BasicAccount

Parameters:

m (str) –

Return type:

BasicAccount

property mnemonic: str

m stands for mnemonic, the string of 25 words that has equivalent information content to the private key

private_key()

A method returning the account’s private key. Equivalent to self.sk

Return type:

str

property sk: str

Shorthand for the account’s private key

class gridworks.algo_utils.MultisigAccount(version, threshold, addresses)

Represents exactly the information to create the public address of a multisig account: the version, threshold and the ordered list of public addresses in the account. The MultiSigAccount is not meant to change. Unlike a BasicAccount, it does not store private information and can be entirely public.

This is different from a algosdk.futures.transaction.Multisig, which stores the latest signatures it knows about in its ordered list of MultisigSubsigs. Using the same Multisig for multiple transactions will result in errors.

Parameters:
  • version (int) – currently, the version is 1

  • threshold (int) – how many signatures are necessary

  • addresses (str[]) – addresses in the multisig account

version
Type:

int

threshold
Type:

int

addresses
Type:

PublicAddress

property addr: str

Return the MultisigAccount address, again piggybacking on multiSig

property addr_short_hand: str

Returns the last 6 characters of the account address.

This is just used for logging messages and human eyes!

address()

Return the account address, again piggybacking on multiSig

Return type:

str

create_mtx(txn)

Returns the MultisigTransaction for this MultisigAccount

Parameters:

txn (<module 'algosdk.future.transaction' from '/home/docs/checkouts/readthedocs.org/user_builds/gridworks/envs/stable/lib/python3.10/site-packages/algosdk/future/transaction.py'>) –

Return type:

MultisigTransaction

validate()

Check if the account is valid by piggybacking on multiSig.validate

Return type:

None

class gridworks.algo_utils.PendingTxnResponse(tx_id, response)

Parses the dict object of a transaction response into a Python class

Parameters:
  • tx_id (str) –

  • response (Dict[str, Any]) –

gridworks.algo_utils.algos(addr)
Parameters:
  • acct (AlgoAccount) – can also be a multiSig

  • addr (str) –

Returns:

Return the number of microAlgos in an account, or None if there is an issue getting this number

Return type:

Optional[int]

gridworks.algo_utils.get_app_global_state(client, app_id)

Returns the global state of an Algorand application

Parameters:
  • client (AlgodClient) – Any AlgodClient

  • app_id (int) – the application id of the smart contract

Returns:

Returns the decoded key/value pairs of an app’s global state (uints and bytes)

Return type:

Dict[bytes, Union[int, bytes]]

gridworks.algo_utils.get_balances(client, addr)

Returns a dictionary of Algorand Standard Asset holdings

Parameters:
  • addr (str) – public address holding the ASAs

  • client (AlgodClient) –

Returns:

A dictionary taking the ids of the held ASAs to the amounts of those ASAs held by the address.

Return type:

Dict[int, int]

gridworks.algo_utils.micro_algos(addr)

Args: acct (AlgoAccount): can also be a multiSig

Returns:

Return the number of microAlgos in an account, or None if there is an issue getting this number

Return type:

Optional[int]

Parameters:

addr (str) –

gridworks.algo_utils.pay_account(client, sender, to_addr, amt_in_micros)

Sends micro algos from one account to another, and waits to

Parameters:
  • client (AlgodClient) – AlgodClient

  • sender (BasicAccount) – algo_utils.BasicAccount (not algo_utils.MultisigAccount)

  • to_addr (str) – public address receiving the algos

  • amtInMicros (int) – Algos * 10**6 getting sent

  • amt_in_micros (int) –

Raises:

errors.AlgoError – raises error if fails to send, if there is a txid discrepancy

Return type:

PendingTxnResponse

Returns: PendingTxnResponse

gridworks.algo_utils.send_signed_mtx(client, mtx)

Combines sending a Multisig transaction (sing send_raw_transaction) with waiting for the transaction to complete, returning a python PendingTxnResponse class object with the response.

Parameters:
  • client (AlgodClient) –

  • mtx (MultisigTransaction) –

Return type:

PendingTxnResponse

gridworks.algo_utils.string_to_algo_addr(input_str)

Encodes a string as an algorand address. Could be used to overload mutable optional address fields in an asset (freeze, reserve, clawback)

Parameters:

input_str (str) – Aribtrary string.

Returns:

AlgoAddressStringFormat

Return type:

str

gridworks.algo_utils.verify_account_exists_and_funded(addr)

Raises an exception if an address is not a valid format, or if the account does not have at least 1 Algo. Note that every account on Algorand must have a minimum balance of 100,000 microAlgos and this minimum balance increases with more holdings.

Parameters:

addr (str) – the Algorand public address in question

Raises:

errors.AlgoError – if addr does not have AlgoAddressStringFormat, or does not have at least 1 Algo.

Return type:

None

gridworks.algo_utils.wait_for_transaction(client, tx_id, timeout=10)

Translates algosdk client.pending_transaction_info into a Python class object PendingTxnResponse after waiting for a confirmed transaction

Parameters:
  • tx_id (str) – id of transaction

  • timeout (int) – rounds to repeat before raising an error and giving up

  • client (AlgodClient) –

Raises:

Exception if transaction is not confirmed in timeout rounds

Return type:

PendingTxnResponse