Skip to content

Blockchain · How-to

How to Write Algorand Smart Signatures in TEAL

Algorand smart signatures are TEAL programs that approve transactions when their rules pass. Learn how to choose a LogicSig type, write and test a restrictive policy, then compile and use it without exposing funds to unintended transactions.

By the SkyBitcoins editorial team · Updated

What does an Algorand smart signature authorize?

On Algorand, a “smart signature” is a LogicSig: a TEAL program that returns approval only when a transaction meets its rules. You do not deploy it as an application. Instead, it authorizes transactions from a program-controlled account or provides restricted, signed approval on behalf of an existing account.

Choose the model before writing code:

  • Contract account: The address is derived from the program. The program controls spending from that account, so you must fund it and protect its assets.
  • Delegated LogicSig: An account signs the program. It can authorize transactions for that account, but only within the program’s conditions. Anyone who gets the signed LogicSig may be able to use it for transactions that pass those conditions.

Both types need careful limits. A LogicSig does not know your intent beyond the rules you encode, and an overly broad rule can approve an unwanted transaction. If you need persistent application state, user-facing app calls or more complex stateful behavior, assess an Algorand application instead of trying to make a LogicSig do that job.

Which rules should your TEAL program enforce?

Write down the authorization policy in plain language before translating it into TEAL. Specify the transaction type, sender or receiver, amount limits, fee ceiling, whether grouping is allowed, and which fields must remain unchanged. For a payment-only example, you might require a single payment to one receiver, cap its amount and fee, and reject rekeying or closing the account.

Use this checklist to narrow the program’s authority:

  1. Allow only the transaction types the signer needs.
  2. Restrict the receiver, asset, application or other relevant fields to expected values.
  3. Set sensible amount and fee bounds; check current network parameters before choosing limits.
  4. Reject RekeyTo and account-closing fields unless your design explicitly needs them.
  5. Decide whether the transaction can be part of a group. If not, require a group size of one.
  6. Consider how the program behaves on each network and with every transaction the signer may submit.

A LogicSig does not automatically make a transaction safe because it uses TEAL. The rules must cover the transaction fields and group behavior that matter to your use case.

How do you write a restrictive TEAL LogicSig?

This example allows one standalone payment to a chosen address, caps the payment and fee, and rejects rekeying and closing the sender’s account. Replace the address with a valid Algorand address and adjust the limits to your policy. The fee value below is an example ceiling in microAlgos, not a statement of the current network fee.

#pragma version 8
global GroupSize
int 1
==
assert
txn TypeEnum
int pay
==
assert
txn Receiver
addr REPLACE_WITH_VALID_ALGORAND_ADDRESS
==
assert
txn Amount
int 0
>
assert
txn Amount
int 100000
<=
assert
txn Fee
int 2000
<=
assert
txn RekeyTo
global ZeroAddress
==
assert
txn CloseRemainderTo
global ZeroAddress
==
assert
int 1
return

TEAL evaluates values on a stack; failed assertions reject the transaction. The example is deliberately narrow and is not a complete template for every payment workflow. In particular, it does not authorize grouped payments, and its fixed receiver and limits may not suit your application. Review the fields your real transaction uses before adapting it.

How should you compile and test the program?

Compile the program with an Algorand-compatible compiler or through an Algod node’s TEAL compile endpoint. The compiler checks syntax and produces the program bytes used to create or sign a LogicSig. Choose a TEAL version supported by the network you will use; do not assume a program compiled for one environment is automatically suitable everywhere.

A practical development sequence is:

  1. Keep the TEAL source under version control and record the intended policy beside it.
  2. Compile it against a local development network or a test network before considering mainnet use.
  3. Create test transactions that should pass, then vary one condition at a time to confirm disallowed transactions fail.
  4. Test boundary values: the exact amount and fee limits, values just above them, zero amounts, unexpected receivers, rekey fields and close fields.
  5. Test grouped transactions explicitly. Confirm whether the program should reject them or validate every relevant group member.
  6. Recompile and rerun tests whenever the source, compiler version or supported TEAL version changes.

A successful compile only confirms that the code can be assembled. It does not prove that the policy is safe, that the transaction fields are correctly constrained or that the program behaves as intended.

How do you attach and use a LogicSig?

After testing, your application builds the transaction, attaches the LogicSig and submits it through an Algorand node or compatible SDK. The exact calls vary by SDK, but the sequence is the same: construct the transaction, set the correct sender and network context, attach the LogicSig authorization, then submit and wait for confirmation. Check the transaction result and logs if it is rejected; do not weaken the policy simply to make an unexplained failure pass.

For a contract-account LogicSig, derive the account address from the compiled program and confirm that it matches the intended sender before funding it. The account must hold enough ALGO for its minimum balance and planned transactions. For a delegated LogicSig, have the account sign the intended program and distribute the signed authorization only as needed. Never share a private key to create or use a delegated signature.

Compilation itself is generally an off-chain development step, not an on-chain deployment. The transactions still incur Algorand network fees, and the account’s minimum-balance requirement can tie up funds. Check current network parameters and SDK behavior before calculating the amount to fund.

How do you limit the risk of a LogicSig?

A LogicSig’s rules are the security boundary. A contract-account program controls funds at its derived address, while a delegated program can serve as a bearer authorization once signed. In either case, anyone who can submit a valid transaction may attempt to use the authorization, so do not rely on a front end or private workflow to enforce restrictions that the TEAL program should enforce.

Before using real assets, inspect the full transaction that will be authorized. Check the sender, receiver, amount, fee, transaction type, rekey and close fields, group membership, and any other field relevant to the policy. If your transaction includes multiple group members, test whether a valid-looking member could be paired with an unintended transfer or other action.

Keep source code and compiled program bytes associated with a version or release so you can verify what was approved. Limit access to signing keys and signed delegated LogicSigs. If you discover a policy flaw, stop using the authorization and follow a recovery plan appropriate to the account type; a deployed or funded contract account may not have a simple “turn off” switch.

What LogicSig mistakes should you avoid?

Most LogicSig failures come from rules that are too broad, testing that misses edge cases or confusion about what is being authorized. Check these mistakes before you use the program:

  • Treating a compile as a security review. Compilation catches syntax errors, not a permissive policy. Test expected and rejected transactions.
  • Checking only the obvious field. A receiver and amount check may still leave rekeying, closing, fees or transaction grouping unconstrained.
  • Allowing groups unintentionally. A program that approves one transaction in a group may be used in a larger combination. Reject groups if the design does not need them, or validate the full group.
  • Using an unsuitable fee ceiling. An arbitrary cap can reject legitimate transactions or permit unexpectedly high fees. Set and test a policy-specific maximum.
  • Sharing a delegated authorization casually. A signed LogicSig is not the same as a private key, but it can still authorize any transaction that passes its program.
  • Using a program account without a funding plan. Account minimum balance and transaction fees affect how much ALGO must remain available.

When you cannot explain exactly which transactions the program accepts, keep it on a development network and revise the policy before using it with valuable assets.

What should you check before using real ALGO?

Before moving from test transactions to a production workflow, confirm that the code, policy and operational setup all match. A LogicSig is a transaction authorization mechanism, not a guarantee against mistakes in the surrounding application or wallet process.

Use this final checklist:

  • The intended account type—contract account or delegated LogicSig—is documented.
  • The program restricts every transaction field that matters to your use case.
  • Tests cover valid transactions, rejected transactions, limit boundaries and group behavior.
  • The compiled program corresponds to the reviewed source and supported TEAL version.
  • The sender and network are checked before submission.
  • Funding covers the account minimum balance and planned network fees, based on current parameters.
  • Private keys and signed delegated LogicSigs are handled according to their different risks.
  • You have a response plan for rejected transactions or a discovered policy flaw.

If those checks are not complete, do not fund a contract account or sign a delegated program with valuable authority. Start with a local or test network, keep the authorization narrow, and only proceed when you can predict what the program will approve.

Frequently asked questions

What is a smart signature on Algorand?

A smart signature, usually called a LogicSig, is a TEAL program that evaluates whether a transaction is allowed. It can authorize transactions from a program-controlled account or, when delegated, act under an account’s signed approval.

Do LogicSigs need to be deployed?

No. A LogicSig is not an Algorand application and does not need an app deployment transaction. You still need to pay the network fees for transactions it authorizes, and a program-controlled account needs enough ALGO to meet the network’s minimum-balance requirement.

What is the difference between a contract account and a delegated LogicSig?

A contract-account LogicSig controls an account whose address is derived from the program. A delegated LogicSig is signed by an existing account, and its program restricts which transactions that approval can authorize.

Can someone else use a delegated LogicSig?

Treat a signed delegated LogicSig as a usable authorization: someone who obtains it may submit transactions that satisfy its rules. Keep it private where appropriate, and make the program narrow enough that disclosure cannot authorize more than intended.

Is TEAL the same as PyTeal?

TEAL is Algorand’s stack-based language for smart-contract logic, including LogicSigs. PyTeal is a higher-level Python framework that can generate TEAL, but you can also write TEAL directly and compile it.

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 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 · Explainer

YuzuSwap Airdrop 2 on Oasis: What to Know in 2026

YuzuSwap was an Oasis Emerald decentralised exchange, but it is now inactive. Here’s how to understand the Airdrop 2 announcement, what you can verify in 2026, and why you should be cautious before connecting a wallet or claiming tokens.

Blockchain · Explainer

Why Are People Bullish on Ethereum in 2026?

The bullish case for Ethereum rests on its role as a programmable settlement network, demand for ETH in fees and staking, and a large app ecosystem. Here’s how to assess that case—and where it can fail.

Blockchain · Explainer

What Is a Zero-Knowledge Proof? A Practical Guide

A zero-knowledge proof lets someone show that a claim is true without sharing the private information behind it. Learn how proofs work, what blockchains use them for, and what they do—and don’t—keep private.

Blockchain · Explainer

Why Is Ontology Different? A Practical Guide

Ontology is a blockchain project, not a general-purpose knowledge graph. Its distinguishing focus is decentralized identity and data, alongside a two-token model that separates network governance from transaction fees.