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.

payment

The key function to facilitate Algo transfers is algorand.send.payment(params) (immediately send a single payment transaction), algorand.createTransaction.payment(params) (construct a payment transaction), or algorand.newGroup().addPayment(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

const result = await algorand.send.payment({

sender: 'SENDERADDRESS',

receiver: 'RECEIVERADDRESS',

amount: (4).algo(),

});

// Advanced example

const result2 = await algorand.send.payment({

sender: 'SENDERADDRESS',

receiver: 'RECEIVERADDRESS',

amount: (4).algo(),

closeRemainderTo: 'CLOSEREMAINDERTOADDRESS',

lease: 'lease',

note: 'note',

// Use this with caution, it's generally better to use algorand.account.rekeyAccount

rekeyTo: 'REKEYTOADDRESS',

// You wouldn't normally set this field

firstValidRound: 1000n,

validityWindow: 10,

extraFee: (1000).microAlgo(),

staticFee: (1000).microAlgo(),

// Max fee doesn't make sense with extraFee AND staticFee

// already specified, but here for completeness

maxFee: (3000).microAlgo(),

// 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: transactionSigner,

maxRoundsToWaitForConfirmation: 5,

suppressLog: true,

});

ensureFunded

The ensureFunded 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

// From account

// Basic example

await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', (1).algo());

// With configuration

await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', (1).algo(), {

minFundingIncrement: (2).algo(),

fee: (1000).microAlgo(),

suppressLog: true,

});

// From environment

// Basic example

await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', (1).algo());

// With configuration

await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', (1).algo(), {

minFundingIncrement: (2).algo(),

fee: (1000).microAlgo(),

suppressLog: true,

});

// TestNet Dispenser API

// Basic example

await algorand.account.ensureFundedUsingDispenserAPI(

'ACCOUNTADDRESS',

algorand.client.getTestNetDispenserFromEnvironment(),

(1).algo(),

);

// With configuration

await algorand.account.ensureFundedUsingDispenserAPI(

'ACCOUNTADDRESS',

algorand.client.getTestNetDispenserFromEnvironment(),

(1).algo(),

{

minFundingIncrement: (2).algo(),

},

);

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

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

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: