Skip to content
HelpfulCoin

Blockchain · How-to

How to Write an Algorand TEAL Logic Signature

A TEAL logic signature is a small program that approves or rejects an Algorand transaction based on rules you define. This guide explains how to write one, test it, and reduce the risk of accidentally authorizing the wrong transaction.

By the HelpfulCoin editorial team · Updated

What is a TEAL logic signature on Algorand?

A TEAL logic signature is a stateless program that decides whether an Algorand transaction is allowed. TEAL, short for Transaction Execution Approval Language, is a stack-based language: instructions place values on a stack, then operate on them. A logic signature evaluates transaction details and must approve the transaction for it to proceed.

Developers commonly use logic signatures to put rules around spending from a program-derived account, or to authorize a transaction with a delegated program. They are useful when the rules can be checked from the transaction group itself. They do not keep application state, such as a changing balance record or a user profile.

A logic signature is different from a stateful Algorand application. Applications use approval and clear-state programs and can work with application state under the rules of the Algorand Virtual Machine. A logic signature is closer to a transaction gate: it checks conditions, then accepts or rejects.

Keep the distinction in mind before writing code. If the policy needs stored data, user interaction across multiple calls, or updates to shared state, an application may be a better design than a logic signature.

How should you plan a logic signature before coding?

Start by deciding exactly which transactions the logic signature should approve; the code should enforce that policy rather than just check that a transaction looks familiar. Write the rules in plain language before translating them into TEAL.

A useful specification answers questions such as:

  • Which transaction types are allowed?
  • Who may send or receive the transaction?
  • Is there a minimum or maximum amount?
  • Can the transaction close an account or rekey it to a different authorizing address?
  • What fee limit should apply, and what other transactions may be in the group?

Then choose between a logic signature and an application. Use a logic signature when the decision depends on information available in the transaction or group. Choose an application when the rules need state or app calls.

Next, write the TEAL program or use PyTeal to express the logic in Python and compile it to TEAL. PyTeal is a way to generate TEAL, not a different kind of on-chain program. In either case, review the compiled program because that is what the Algorand Virtual Machine executes. Use a current Algorand compiler and tooling that match the target network’s supported TEAL version.

How do you write a simple TEAL payment rule?

Write a logic signature by translating each policy rule into a check that must be true before the program approves the transaction. For example, a basic payment policy might require a payment transaction, a specific recipient, a maximum amount, and no close-out or rekey operation.

A schematic TEAL pattern looks like this:

#pragma version 9
txn TypeEnum
int pay
==
txn Receiver
addr REPLACE_WITH_VALID_RECIPIENT
==
&&
txn Amount
int MAX_AMOUNT_IN_MICROALGOS
<=
&&
txn CloseRemainderTo
global ZeroAddress
==
&&
txn RekeyTo
global ZeroAddress
==
&&

This is a template, not deployable code: replace the recipient and amount placeholders with valid constants before compiling. The checks are combined with &&, so every condition must pass. The example does not limit transaction fees or inspect other transactions in a group; add those checks if the policy requires them.

Be precise about units: Algorand amounts are expressed in microAlgos, the smallest unit of ALGO. Also decide whether a zero-value payment is acceptable. A maximum-only amount check does not set a minimum.

How do you test a TEAL logic signature safely?

Test a logic signature against both transactions it should approve and transactions it must reject before using it with funds. A program that compiles can still enforce the wrong policy, so compilation is only one part of verification.

A practical test sequence is:

  1. Compile the TEAL with the intended AVM version and inspect the compiled output.
  2. Simulate an allowed transaction using the Algorand development tools or a test environment.
  3. Change one field at a time—such as recipient, amount, transaction type, fee, close address, or rekey address—and check that the program rejects it.
  4. Test transaction groups if the program relies on group contents; do not assume a rule about one transaction automatically constrains every transaction in the group.
  5. Review edge cases, including boundary amounts, missing or unexpected fields, and fees.

For a program that controls funds, ask another developer to review the policy and test cases. Automated tests help catch regressions when code changes, but they do not prove that the design is safe. Do not send valuable assets to a program address until its compiled program and authorization behavior have been independently reviewed.

How do you use a logic signature without risking funds?

Use a logic signature only after checking that the compiled program and the transaction authorization method match the intended policy. A logic signature’s address is derived from its program, so changing the program can change the address and create a different account. Confirm the program and address before funding or signing transactions.

A logic signature may be used as a program account, or it may be delegated by a private key that signs the program. These approaches have different trust assumptions. With a delegated program, protect the delegating key as carefully as any key that can authorize transactions. Do not share seed phrases or private keys with a compiler, website, or support contact.

Before signing, inspect the transaction’s sender, receiver, amount, fee, close-out fields, rekey field, and group contents. Confirm that the program approves only what you intend. Keep a copy of the source, compiled program, version information, and test results so future changes can be compared.

If the program will manage substantial value or complex transaction groups, get an independent security review. Algorand execution rules and tooling can change, so check compatibility with the network and AVM version you plan to use.

What mistakes should you avoid when writing TEAL?

The most common mistakes are broad rules, untested assumptions, and treating a successful compile as proof of safety. A logic signature is only as restrictive as its checks.

Watch out for these problems:

  • Checking only the transaction type: a payment rule that does not constrain the receiver may permit payments to an unintended address.
  • Forgetting close-out and rekey fields: a payment can include account-management effects as well as an amount and recipient.
  • Ignoring fees or transaction groups: a program may approve a transaction with an excessive fee or fail to constrain other group members.
  • Confusing ALGO with microAlgos: an amount written in the wrong unit can be far larger or smaller than intended.
  • Assuming a logic signature has state: it cannot replace an application when a rule depends on stored, changing data.
  • Using unreviewed code with real funds: a typo or missing condition can have lasting consequences once assets are sent to the program account.

Keep the policy short and explicit. For every condition, write at least one test where it passes and one where it fails. If a requirement is difficult to express and verify, reconsider whether a logic signature is the right tool.

When should you use an application instead of a logic signature?

Use a stateful Algorand application when the contract needs to maintain or update shared state; use a logic signature when transaction-only checks are enough. The two designs solve different problems, and choosing the simpler one reduces the chance of building the wrong authorization model.

A logic signature is a good candidate when its decision can be made from transaction fields and, where relevant, the transaction group. Examples include restricting the recipient or amount of a payment, or requiring a transaction to meet a narrow set of conditions.

An application is usually more suitable when the rules depend on stored values, such as a changing allowance, a record of prior actions, or data updated during execution. Applications can also have more complex call flows, but their state and execution rules need careful design and testing.

A useful design check is to describe what information the program needs to approve a transaction. If all of it is available in the transaction context, a logic signature may work. If the program must remember what happened before or modify persistent data, use an application or redesign the flow. Do not add a stateful app merely for complexity, but do not force state-dependent rules into a stateless signature.

Frequently asked questions

What is an Algorand logic signature?

A logic signature is a stateless TEAL program that evaluates a transaction or transaction group and returns approval or rejection. It can control when funds at its program address may be spent, but it does not store or update application state.

Is TEAL the same thing as a logic signature?

No. TEAL is Algorand’s stack-based virtual-machine language, and it can be used for different kinds of on-chain programs. Logic signatures are one use; stateful smart contracts, also called applications, use approval and clear-state programs.

Can a logic signature control Algorand funds?

A logic signature can authorize spending from the address derived from its program, so an error can expose funds held at that address. A delegated logic signature also relies on the security of the key that signed the program.

Can I write a logic signature in Python?

Yes. PyTeal lets developers write Algorand contract logic in Python and compile it to TEAL. The resulting program still needs to be checked and tested as TEAL before it is used.

Can a logic signature read or change app state?

A logic signature evaluates transaction details, not application state. If a rule depends on stored data or needs to change state, a stateful Algorand application is usually the better fit.

Keep reading

Related guides

All blockchain guides

Blockchain · How-to

How to Build an Algorand PyTeal Smart Signature

An Algorand smart signature is a small TEAL program that decides whether a transaction is authorized. PyTeal lets you write that program with Python-style expressions, then compile and test it before using it with an Algorand account.

Blockchain · Explainer

What Is an Algorand Game Hackathon in 2026?

An Algorand game hackathon is a short, team-based event for building and presenting a game that uses Algorand. Learn what to expect, how to check whether an event is open in 2026, and how to prepare and build safely.

Blockchain · Explainer

How Does Algorand Staking Work in 2026?

Algorand introduced protocol staking rewards in 2025 to encourage participation in network security. Learn how the rewards work, what you need to do to take part, and what risks and older reward programs to keep separate.

Blockchain · How-to

How to Start Algorand dApp Development

Algorand dApp development combines smart contracts on the Algorand Virtual Machine with apps that submit transactions through wallets. Start on a local network or TestNet, learn the account and fee model, then deploy to MainNet only after thorough testing.

Blockchain · Explainer

What Is zkBTC? Bitcoin EVM Layer 2 Explained

zkBTC is described as a Bitcoin-focused EVM layer 2, but its technical design and operating status are not published. Learn what that kind of network can do, what it cannot guarantee, and what to check before connecting a wallet or moving funds.

Blockchain · Explainer

Why Are People Bullish on Ethereum in 2026?

People are bullish on Ethereum because it is a widely used platform for crypto apps, payments and digital assets, with ETH playing a role in its operation. That case is not a promise of higher prices: competition, fees and technical risks still matter.