Algo transfers (payments) | Algorand Developer Portal

Algo transfers (payments)

Algo transfers, or payments, is a higher-order use case capability provided by AlgoKit Utils that builds on top of the core capabilities, particularly Algo amount handling and Transaction management. It allows you to easily initiate Algo transfers between accounts, including dispenser management and idempotent account funding.

To see some usage examples check out the automated tests in the repository.

payment

Section titled “payment”

The key function to facilitate Algo transfers is algorand.send.payment(params) (immediately send a single payment transaction), algorand.create_transaction.payment(params) (construct a payment transaction), or algorand.new_group().add_payment(params) (add payment to a group of transactions) per AlgorandClient transaction semantics.

The base type for specifying a payment transaction is PaymentParams, which has the following parameters in addition to the common transaction parameters:

# Minimal example

result = algorand_client.send.payment(

PaymentParams(

sender="SENDERADDRESS",

receiver="RECEIVERADDRESS",

amount=AlgoAmount(algo=4)

)

)

# Advanced example

result2 = algorand_client.send.payment(

PaymentParams(

sender="SENDERADDRESS",

receiver="RECEIVERADDRESS",

amount=AlgoAmount(algo=4),

close_remainder_to="CLOSEREMAINDERTOADDRESS",

lease="lease",

note=b"note",

# Use this with caution, it's generally better to use algorand_client.account.rekey_account

rekey_to="REKEYTOADDRESS",

# You wouldn't normally set this field

first_valid_round=1000,

validity_window=10,

extra_fee=AlgoAmount(micro_algo=1000),

static_fee=AlgoAmount(micro_algo=1000),

# Max fee doesn't make sense with extra_fee AND static_fee

# already specified, but here for completeness

max_fee=AlgoAmount(micro_algo=3000),

# Signer only needed if you want to provide one,

# generally you'd register it with AlgorandClient

# against the sender and not need to pass it in

signer=transaction_signer,

),

send_params=SendParams(

max_rounds_to_wait=5,

suppress_log=True,

)

)

ensure_funded

Section titled “ensure_funded”

The ensure_funded function automatically funds an account to maintain a minimum amount of disposable Algo. This is particularly useful for automation and deployment scripts that get run multiple times and consume Algo when run.

There are 3 variants of this function:

The general structure of these calls is similar, they all take:

Examples

Section titled “Examples”

# From account

# Basic example

algorand_client.account.ensure_funded("ACCOUNTADDRESS", "DISPENSERADDRESS", AlgoAmount(algo=1))

# With configuration

algorand_client.account.ensure_funded(

"ACCOUNTADDRESS",

"DISPENSERADDRESS",

AlgoAmount(algo=1),

min_funding_increment=AlgoAmount(algo=2),

fee=AlgoAmount(micro_algo=1000),

send_params=SendParams(

suppress_log=True,

),

)

# From environment

# Basic example

algorand_client.account.ensure_funded_from_environment("ACCOUNTADDRESS", AlgoAmount(algo=1))

# With configuration

algorand_client.account.ensure_funded_from_environment(

"ACCOUNTADDRESS",

AlgoAmount(algo=1),

min_funding_increment=AlgoAmount(algo=2),

fee=AlgoAmount(micro_algo=1000),

send_params=SendParams(

suppress_log=True,

),

)

# TestNet Dispenser API

# Basic example

algorand_client.account.ensure_funded_from_testnet_dispenser_api(

"ACCOUNTADDRESS",

algorand_client.client.get_testnet_dispenser_from_environment(),

AlgoAmount(algo=1)
)

# With configuration

algorand_client.account.ensure_funded_from_testnet_dispenser_api(

"ACCOUNTADDRESS",

algorand_client.client.get_testnet_dispenser_from_environment(),

AlgoAmount(algo=1),

min_funding_increment=AlgoAmount(algo=2),
)

All 3 variants return an EnsureFundedResponse (and the first two also return a single transaction result) if a funding transaction was needed, or None if no transaction was required:

If you are using the TestNet Dispenser API then the transaction_id is useful if you want to use the refund functionality.

Dispenser

Section titled “Dispenser”

If you want to programmatically send funds to an account so it can transact then you will often need a “dispenser” account that has a store of Algo that can be sent and a private key available for that dispenser account.

There’s a number of ways to get a dispensing account in AlgoKit Utils: