template
- class Split(owner: str, receiver_1: str, receiver_2: str, rat_1: int, rat_2: int, expiry_round: int, min_pay: int, max_fee: int)
Bases:
algosdk.template.Template
Split allows locking algos in an account which allows transfering to two predefined addresses in a specified ratio such that for the given ratn and ratd parameters we have:
first_recipient_amount * rat_2 == second_recipient_amount * rat_1
Split also has an expiry round, after which the owner can transfer back the funds.
- Parameters
owner (str) – an address that can receive the funds after the expiry round
receiver_1 (str) – first address to receive funds
receiver_2 (str) – second address to receive funds
rat_1 (int) – how much receiver_1 receives (proportionally)
rat_2 (int) – how much receiver_2 receives (proportionally)
expiry_round (int) – the round on which the funds can be transferred back to owner
min_pay (int) – the minimum number of microalgos that can be transferred from the account to receiver_1
max_fee (int) – half the maximum fee that can be paid to the network by the account
- get_program()
Return a byte array to be used in LogicSig.
- static get_split_funds_transaction(contract, amount: int, fee: int, first_valid, last_valid, gh)
Return a group transactions array which transfers funds according to the contract’s ratio. :param amount: total amount to be transferred :type amount: int :param fee: fee per byte :type fee: int :param first_valid: first round where the transactions are valid :type first_valid: int :param gh: genesis hash in base64 :type gh: str
- Returns
Transaction[]
- class HTLC(owner: str, receiver: str, hash_function: str, hash_image: str, expiry_round: int, max_fee: int)
Bases:
algosdk.template.Template
Hash Time Locked Contract allows a user to recieve the Algo prior to a deadline (in terms of a round) by proving knowledge of a special value or to forfeit the ability to claim, returning it to the payer.
This contract is usually used to perform cross-chained atomic swaps.
- More formally, algos can be transfered under only two circumstances:
To receiver if hash_function(arg_0) = hash_value
To owner if txn.FirstValid > expiry_round
- Parameters
owner (str) – an address that can receive the asset after the expiry round
receiver (str) – address to receive Algos
hash_function (str) – the hash function to be used (must be either sha256 or keccak256)
hash_image (str) – the hash image in base64
expiry_round (int) – the round on which the assets can be transferred back to owner
max_fee (int) – the maximum fee that can be paid to the network by the account
- get_program()
Return a byte array to be used in LogicSig.
- static get_transaction(contract, preimage, first_valid, last_valid, gh, fee)
Return a transaction which will release funds if a matching preimage is used.
- Parameters
contract (bytes) – the contract containing information, should be received from payer
preimage (str) – the preimage of the hash in base64
first_valid (int) – first valid round for the transactions
last_valid (int) – last valid round for the transactions
gh (str) – genesis hash in base64
fee (int) – fee per byte
- Returns
- transaction to claim algos from
contract account
- Return type
- class DynamicFee(receiver: str, amount: int, first_valid: int, last_valid: Optional[int] = None, close_remainder_address: Optional[str] = None)
Bases:
algosdk.template.Template
DynamicFee contract allows you to create a transaction without specifying the fee. The fee will be determined at the moment of transfer.
- Parameters
receiver (str) – address to receive the assets
amount (int) – amount of assets to transfer
first_valid (int) – first valid round for the transaction
last_valid (int, optional) – last valid round for the transaction (defaults to first_valid + 1000)
close_remainder_address (str, optional) – the address that recieves the remainder
- get_program()
Return a byte array to be used in LogicSig.
- static get_transactions(txn, lsig, private_key, fee)
Create and sign the secondary dynamic fee transaction, update transaction fields, and sign as the fee payer; return both transactions.
- Parameters
txn (Transaction) – main transaction from payer
lsig (LogicSig) – signed logic received from payer
private_key (str) – the secret key of the account that pays the fee in base64
fee (int) – fee per byte, for both transactions
- sign_dynamic_fee(private_key, gh)
Return the main transaction and signed logic needed to complete the transfer. These should be sent to the fee payer, who can use get_transactions() to update fields and create the auxiliary transaction.
- Parameters
private_key (bytes) – the secret key to sign the contract in base64
gh (str) – genesis hash, in base64
- class PeriodicPayment(receiver: str, amount: int, withdrawing_window: int, period: int, max_fee: int, timeout: int)
Bases:
algosdk.template.Template
PeriodicPayment contract enables creating an account which allows the withdrawal of a fixed amount of assets every fixed number of rounds to a specific Algrorand Address. In addition, the contract allows to add timeout, after which the address can withdraw the rest of the assets.
- Parameters
receiver (str) – address to receive the assets
amount (int) – amount of assets to transfer at every cycle
withdrawing_window (int) – the number of blocks in which the user can withdraw the asset once the period start (must be < 1000)
period (int) – how often the address can withdraw assets (in rounds)
fee (int) – maximum fee per transaction
timeout (int) – a round in which the receiver can withdraw the rest of the funds after
- get_program()
Return a byte array to be used in LogicSig.
- static get_withdrawal_transaction(contract, first_valid, gh, fee)
Return the withdrawal transaction to be sent to the network.
- Parameters
contract (bytes) – contract containing information, should be received from payer
first_valid (int) – first round the transaction should be valid; this must be a multiple of self.period
gh (str) – genesis hash in base64
fee (int) – fee per byte
- class LimitOrder(owner: str, asset_id: int, ratn: int, ratd: int, expiry_round: int, max_fee: int, min_trade: int)
Bases:
algosdk.template.Template
Limit Order allows to trade Algos for other assets given a specific ratio; for N Algos, swap for Rate * N Assets.
- Parameters
owner (str) – an address that can receive the asset after the expiry round
asset_id (int) – asset to be transfered
ratn (int) – the numerator of the exchange rate
ratd (int) – the denominator of the exchange rate
expiry_round (int) – the round on which the assets can be transferred back to owner
max_fee (int) – the maximum fee that can be paid to the network by the account
min_trade (int) – the minimum amount (of Algos) to be traded away
- get_program()
Return a byte array to be used in LogicSig.
- static get_swap_assets_transactions(contract: bytes, asset_amount: int, microalgo_amount: int, private_key: str, first_valid, last_valid, gh, fee)
Return a group transactions array which transfer funds according to the contract’s ratio.
- Parameters
contract (bytes) – the contract containing information, should be received from payer
asset_amount (int) – the amount of assets to be sent
microalgo_amount (int) – the amount of microalgos to be received
private_key (str) – the secret key to sign the contract
first_valid (int) – first valid round for the transactions
last_valid (int) – last valid round for the transactions
gh (str) – genesis hash in base64
fee (int) – fee per byte
- put_uvarint(buf, x)
- inject(orig, offsets, values, values_types)