Skip to content

Blockchain · How-to

How to Build an Algorand PyTeal Smart Signature

A PyTeal smart signature is a transaction policy, not a stateful Algorand app. Learn how to write a basic rule, compile it, test it and fund its logic-signature account without overlooking the risks.

By the SkyBitcoins editorial team · Updated

Illustration for How to Build an Algorand PyTeal Smart Signature

Should you use a smart signature or an Algorand app?

An Algorand smart signature is a TEAL program that decides whether a transaction or transaction group may spend from its program-derived address. PyTeal lets you write the rule in Python and compile it to TEAL. Start by deciding whether your requirement is truly stateless: the program can inspect the transaction and group it is authorizing, but it cannot keep application state between transactions.

A smart signature can suit a narrow policy, such as limiting payment transactions from a dedicated account. It is not a general replacement for a stateful smart contract application. If your design needs persistent records, application calls or logic that depends on stored state, investigate an application instead.

Before writing code, answer these questions:

  • Which transaction types should be allowed?
  • Which fields must be constrained, such as amount, receiver, fee or rekeying?
  • Should the rule apply to one transaction or a group?
  • What is the recovery plan if the program does not authorize the transaction you expect?

Treat the answers as a security specification. Any condition you forget may leave the program more permissive than you intended.

What do you need before writing PyTeal?

Set up Python, PyTeal and access to an Algorand node or compatible Algod service. The node’s compile endpoint turns TEAL source into compiled program bytes and provides information used to derive the program address. Check that your PyTeal release and the TEAL version you select are supported by the network environment you plan to use.

Keep your project separate from any wallet or production credentials. A simple layout could include a Python file for the policy, a tests directory and a README recording the intended rules. Use a virtual environment so project dependencies do not affect other Python work.

A practical setup checklist:

  1. Install Python and create a project-specific virtual environment.
  2. Install PyTeal and pin the version used for development.
  3. Configure an Algod endpoint for compilation and testing; keep any access token out of source control.
  4. Choose a test environment before handling real funds.
  5. Record the intended TEAL version and program behavior.

You can write the policy before connecting to a funded account. Do not put a private key, wallet recovery phrase or provider secret in your PyTeal source or a public repository.

How do you write a basic PyTeal signature policy?

Begin with a deliberately narrow rule. This example accepts only a single payment transaction, caps its amount and fee, and rejects rekeying or closing the account. The amounts are in microAlgos: 1,000,000 microAlgos equals 1 ALGO. The fee cap is an example, not a recommendation; adjust it to the policy and current network rules.

from pyteal import *

MAX_PAYMENT = Int(1_000_000)
MAX_FEE = Int(1_000)

program = And(
    Global.group_size() == Int(1),
    Txn.type_enum() == TxnType.Payment,
    Txn.amount() > Int(0),
    Txn.amount() <= MAX_PAYMENT,
    Txn.fee() <= MAX_FEE,
    Txn.rekey_to() == Global.zero_address(),
    Txn.close_remainder_to() == Global.zero_address(),
)

print(compileTeal(program, mode=Mode.Signature, version=8))

This policy permits payment to any receiver. Add an explicit receiver check if payments should go to a particular address, and test that check with both permitted and disallowed addresses. The example also rejects grouped transactions; remove or change that condition only if your intended policy covers groups and you have tested the implications.

How do you compile the TEAL and derive its address?

PyTeal’s compileTeal produces TEAL source; that is not yet the compiled program you use to derive a logic-signature address. Submit the TEAL to an Algod-compatible compile endpoint, check that compilation succeeds, and retain the exact source, compiled result and chosen TEAL version together. Compare the output with your policy: compilation success does not prove the policy is safe.

Use the compiled program to derive the logic-signature address. That address is determined by the program, so even a small policy change creates a different address. Do not fund an address until you have checked that it corresponds to the reviewed program and understand how funds can be spent under its rules.

For a useful review, map each condition to a requirement:

Policy check What it limits
Transaction type Allows only payments
Amount and fee Caps the transaction values
Rekey and close fields Prevents changing authorization or closing the account
Group size Restricts the rule to a single transaction

If the compiled output does not match the intended conditions, stop and review the source before proceeding.

How should you test a smart signature before funding it?

Test the rule as a set of allowed and rejected cases, not just as one successful payment. A useful test suite includes the smallest allowed payment, the amount limit, an amount above the limit, a non-payment transaction, a fee above the cap, a rekey attempt, an account-close attempt and a grouped transaction. For every rejection, confirm which rule should reject it.

Use an Algorand testing environment before placing funds at the program address. Algorand’s Python testing tools support smart-signature tests, and a local network or test network can help you exercise transactions in a fuller environment. Check test-tool compatibility with your PyTeal and TEAL versions. Test compiled behavior as well as Python-level expectations; the on-chain program is the compiled TEAL.

Before any real deployment, have another developer review the policy and test cases if the funds matter. Ask them to look for missing constraints, unintended group behavior and ways a transaction could satisfy the program while violating your business intent. Never treat a green test run as proof that the program is secure.

How do you deploy and use the logic-signature account?

Once the program is reviewed and tested, compile it using the environment you intend to use and verify its derived address again. Fund that address only with an amount appropriate for the test or use case. An account needs enough balance to meet Algorand’s current minimum-balance rules, and transactions also need ALGO for fees. Confirm current network requirements before sending funds.

To spend from the logic-signature account, construct a transaction that satisfies the program and authorize it with the matching logic signature using an Algorand SDK or compatible wallet workflow. The signature is not a private key: the program itself is the authorization rule. A transaction that fails any required condition will not be authorized.

Use this deployment order:

  1. Freeze and review the source code.
  2. Compile it and check the resulting program and address.
  3. Test a small transaction in a non-production environment.
  4. Confirm the destination, amount, fee and account-balance requirements.
  5. Fund the intended address and monitor the transaction result.

Keep a copy of the exact source and compiled program associated with the funded address.

What costs and account constraints should you plan for?

Budget for development access and network activity. PyTeal is used to create TEAL, while a node or service is needed to compile it and submit or inspect transactions. Algod access may have provider-specific terms or costs, so check those before building around a service. On-chain transactions pay fees in ALGO under current protocol rules; the required amount can depend on network conditions and transaction structure.

The account may also need a minimum balance to remain usable. Do not assume that sending all its ALGO to another address is possible: a transaction that closes the account has to be allowed by the program, and this example explicitly rejects account closure. Plan how funds will be managed before depositing them.

The main operational risk is a policy that is either too broad or too restrictive. A broad rule can authorize an unintended payment; a restrictive rule can prevent the transaction you need. Because the address follows the program, changing the code does not update an existing funded address. If you need a new policy, you will have to use its new address and arrange a valid way to move any funds from the old one.

What mistakes should you avoid before funding the address?

The common mistakes are easy to prevent if you review the transaction fields and recovery plan before funding the account.

  • Allowing more than you meant to: State every allowed transaction type and constrain relevant fields, including receiver, amount, fee, rekeying and close behavior.
  • Ignoring transaction groups: A rule that checks one transaction may behave differently when it is part of a group. Decide whether groups are allowed and test the full group.
  • Treating sample limits as network rules: Example amount and fee caps are policy choices. Check current network requirements and set limits that meet your use case.
  • Funding before verifying the address: Derive the address from the reviewed compiled program and confirm it before transferring ALGO or other assets.
  • Assuming the code can be changed later: A different program produces a different address. Plan the movement of funds and do not rely on an untested recovery route.
  • Putting secrets in code: The program is not a place to store private keys or service credentials.

Keep the specification, source, tests, compiled output and address together. That record helps you verify which policy controls the account and investigate an unexpected rejection.

Frequently asked questions

What is an Algorand smart signature?

A smart signature is a TEAL program that approves or rejects a transaction or transaction group. The program’s address can hold ALGO, and a transaction spending from that address must satisfy the program’s rules.

What does PyTeal do?

PyTeal lets you express TEAL logic in Python, then compile that expression into TEAL. It is a development tool, not a separate on-chain programming language or a replacement for testing the compiled program.

Can a smart signature store data between transactions?

No. A smart signature is stateless: it evaluates the transaction or group being authorized and cannot maintain application state between transactions. Use an Algorand smart contract application if your design needs persistent state or app-call logic.

What does it cost to use a smart signature?

There is no universal development price. You may have costs for an Algod endpoint or provider, and transactions require ALGO fees under the network’s current rules. A logic-signature account may also need funding and must meet the network’s minimum-balance requirements.

Can I update a smart signature after deployment?

The program address is derived from the program, so changing the policy means compiling a different program with a different address. Plan a safe way to move funds before relying on a logic signature to hold assets; do not assume you can edit or recover its code like a wallet key.

Mentioned in this guide

dApps in this guide

Derive logo

Derive

Derivatives

Score 6.7 out of 10

Derive offers Ethereum options and perps with self-custody, but confirm its fees, collateral rules and access terms before trading.

Ethereum

Keep reading

Related guides

All blockchain guides

Blockchain · How-to

How to Build an Algorand dApp: A 2026 Guide

Start with a small, testable use case, then choose your Algorand tools, write and test the contract, and connect a wallet. This guide covers the decisions that affect cost, security and deployment in 2026.

Blockchain · Explainer

How to Build a Game Dapp for an Algorand Hackathon

An Algorand game hackathon can help you turn a small playable idea into a working dapp, but event dates, rules and prizes must be checked with the organizer. Use this guide to choose a buildable game, set up your tools and prepare a credible submission.

Blockchain · Explainer

How to Join Algorand’s Build-A-Bull Hackathon

Build-A-Bull is described as a virtual Algorand hackathon with a reported $200,000 USDC prize pool. Before you commit, confirm that registration and submissions are still open: the available event details do not establish its current deadline or status.

Blockchain · Explainer

How Algorand Staking Rewards Work in 2026

Algorand’s newer staking rewards launched in 2025, so they are no longer a future proposal. Here’s how the reward schedule works, what participation may involve, and what to check before committing ALGO or relying on a staking provider.

Blockchain · How-to

How to Manage Algorand Standard Assets in a dApp

Algorand Standard Assets are native tokens, but creating one is only the first step. Plan its settings and authority roles, test the full lifecycle, then monitor opt-ins, balances and administrative permissions.

Blockchain · Explainer

How to assess Algorand’s 2022 FIFA World Cup deal

Algorand’s 2022 FIFA World Cup relationship combined a regional sponsorship with a blockchain partnership, and a World Cup NFT collection used the network. Here’s what that meant for fans—and how to treat the deal as historical context in 2026.

Blockchain · Chain guide

Aptos Blockchain Guide: How to Use Aptos in 2026

Aptos is a Layer 1 blockchain for apps and digital assets, with APT used for transaction fees, staking and governance. This guide explains how to choose a wallet, fund it safely, use apps, understand costs and avoid common risks in 2026.