future.template

class Template

Bases: object

get_address()

Return the address of the contract.

get_program()
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.future.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, sp)

Return a group transactions array which transfers funds according to the contract’s ratio.

Parameters:
  • amount (int) – total amount to be transferred
  • sp (SuggestedParams) – suggested params from algod
Returns:

Transaction[]

class HTLC(owner: str, receiver: str, hash_function: str, hash_image: str, expiry_round: int, max_fee: int)

Bases: algosdk.future.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:
  1. To receiver if hash_function(arg_0) = hash_value
  2. 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, sp)

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
  • sp (SuggestedParams) – suggested params from algod
Returns:

transaction to claim algos from

contract account

Return type:

LogicSigTransaction

class DynamicFee(receiver: str, amount: int, sp, close_remainder_address: str = None)

Bases: algosdk.future.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
  • sp (SuggestedParams) – suggested params from algod
  • 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)

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
class PeriodicPayment(receiver: str, amount: int, withdrawing_window: int, period: int, max_fee: int, timeout: int)

Bases: algosdk.future.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, sp)

Return the withdrawal transaction to be sent to the network.

Parameters:
  • contract (bytes) – contract containing information, should be received from payer
  • sp (SuggestedParams) – suggested params from algod; the value of sp.last will not be used. Instead, the last valid round will be calculated from first valid round and withdrawing window
class LimitOrder(owner: str, asset_id: int, ratn: int, ratd: int, expiry_round: int, max_fee: int, min_trade: int)

Bases: algosdk.future.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, sp)

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
  • sp (SuggestedParams) – suggested params from algod
put_uvarint(buf, x)
inject(orig, offsets, values, values_types)