Skip to content

Transactions

← Back to Examples Overview

Low-level transaction construction and signing.

ExampleDescription
Payment Transaction

This example demonstrates how to send ALGO between accounts using the transact package. It shows the low-level transaction construction pattern with:

  • Transaction wrapper with PaymentTransactionFields for receiver and amount
  • TransactionType.Payment for the transaction type
  • assign_fee() to set transaction fee from suggested params
  • Manual signing and submission

Prerequisites:

Payment with Close

This example demonstrates how to close an account by transferring all remaining ALGO to another account using the close_remainder_to field in PaymentTransactionFields.

Key concepts:

  • close_remainder_to: Specifies an account to receive all remaining ALGO after the transaction
  • When an account is closed, its balance becomes 0
  • The close-to account receives: (original balance - sent amount - fee)

Prerequisites:

Asset Create

This example demonstrates how to create a new Algorand Standard Asset (ASA) using the transact package. It shows the low-level transaction construction pattern with:

  • Transaction wrapper with AssetConfigTransactionFields for all configuration options
  • TransactionType.AssetConfig for the transaction type
  • Retrieving created asset ID from pending transaction info
  • Verifying asset parameters and creator holdings

Prerequisites:

Asset Transfer

This example demonstrates the full asset transfer flow using the transact package: 1. Create a new Algorand Standard Asset (ASA) 2. Opt-in: receiver sends 0 amount of the asset to themselves 3. Transfer assets from creator to the opted-in receiver 4. Verify receiver’s asset balance after transfer

Uses Transaction wrapper with AssetConfigTransactionFields, AssetTransferTransactionFields, and PaymentTransactionFields.

Prerequisites:

Asset Freeze

This example demonstrates how to freeze and unfreeze asset holdings using the transact package: 1. Create an asset with freeze address set 2. Transfer assets to another account 3. Freeze the account’s asset holdings (prevent transfers) 4. Verify frozen account cannot transfer 5. Unfreeze the account’s asset holdings 6. Verify account can transfer after unfreeze

Uses AssetFreezeTransactionFields with TransactionType.AssetFreeze.

Prerequisites:

Asset Clawback

This example demonstrates how to clawback assets from an account using the clawback address and the transact package: 1. Create an asset with clawback address set 2. Transfer assets to a target account 3. Clawback assets from target account using asset_sender field 4. Verify target account balance decreased 5. Verify clawback receiver received the assets

Uses AssetTransferTransactionFields with the asset_sender field for clawback operations.

Prerequisites:

Atomic Transaction Group

This example demonstrates how to group multiple transactions atomically. All transactions in a group either succeed together or fail together. It shows:

  • Creating multiple payment transactions
  • Using group_transactions() to assign a group ID
  • Signing all transactions with the same signer
  • Submitting as a single atomic group

Prerequisites:

Atomic Swap

This example demonstrates how to perform an atomic swap of ALGO for ASA between two parties. In an atomic swap:

  • Party A sends ASA to Party B
  • Party B sends ALGO to Party A
  • Each party signs ONLY their own transaction
  • Signatures are combined and submitted together
  • Both transfers succeed or both fail (atomicity)

Key difference from regular atomic groups: different parties sign different transactions.

Prerequisites:

Single Signature

This example demonstrates how to create an ed25519 keypair and sign transactions using the low-level transact package APIs.

Key concepts:

  • Creating a keypair using nacl (ed25519 signature scheme)
  • Using generate_address_with_signers() to derive an Algorand address from the public key
  • Understanding the relationship between ed25519 public key and Algorand address
  • Signing transactions with a raw ed25519 signer function

Prerequisites:

Multisig

This example demonstrates how to create and use a 2-of-3 multisig account.

Key concepts:

  • Creating a MultisigAccount with version, threshold, and addresses
  • Deriving the multisig address from the participant addresses
  • Signing transactions with a subset of participants (2 of 3)
  • Demonstrating that insufficient signatures (1 of 3) will fail

Prerequisites:

Logic Signature

This example demonstrates how to use a logic signature (lsig) to authorize transactions.

Key concepts:

  • Compiling a TEAL program using algod.teal_compile()
  • Creating a LogicSig from compiled program bytes
  • Understanding the logic signature address (derived from program hash)
  • Funding and using a logic signature as a standalone account
  • Creating a delegated logic signature where an account delegates signing to a program

Logic signatures allow transactions to be authorized by a program instead of (or in addition to) a cryptographic signature. This enables smart contracts that can hold and send funds based purely on program logic.

Prerequisites:

Fee Calculation

This example demonstrates how to estimate transaction size and calculate fees using the transact package:

  • estimate_transaction_size() to get estimated byte size
  • calculate_fee() with different fee parameters
  • assign_fee() to set fee on transaction
  • How fee_per_byte, min_fee, extra_fee, and max_fee work
  • Compare estimated vs actual transaction sizes

Prerequisites:

Encoding/Decoding

This example demonstrates how to serialize and deserialize transactions using the transact package:

  • encode_transaction() to get msgpack bytes with TX prefix
  • encode_transaction_raw() to get msgpack bytes without prefix
  • decode_transaction() to reconstruct transaction from bytes
  • encode_signed_transaction() and decode_signed_transaction() for signed transactions
  • tx_id() for calculating transaction ID

Prerequisites:

Application Call

This example demonstrates how to deploy and interact with a smart contract on Algorand using the transact package:

  • Compile simple approval and clear TEAL programs using algod.teal_compile()
  • Create an app with TransactionType.AppCall and OnApplicationComplete.NoOp
  • Use Transaction with application_call=AppCallTransactionFields(…)

including approval_program, clear_state_program, global_state_schema, and local_state_schema

  • Retrieve the created app ID from pending transaction info
  • Call the app with application arguments
  • Demonstrate OnApplicationComplete.OptIn for local state
  • Delete the app at the end

Prerequisites:

Run any example from the repository’s examples directory:

Terminal window
cd examples
uv run python transact/01_payment_transaction.py