Smart Contracts Overview
Understanding smart contracts on the Algorand blockchain
What are Algorand Smart Contracts?
Algorand Smart Contracts (ASC1) are self-executing programs deployed on the Algorand blockchain that enable developers to build secure, scalable decentralized applications. Smart contracts on Algorand can be written in Algorand TypeScript, Algorand Python, or directly in TEAL. Smart contract code written in TypeScript or Python is compiled to TEAL, an assembly-like language that is interpreted by the Algorand Virtual Machine (AVM) running within an Algorand node.
Smart contracts are separated into two main categories: Applications and Logic Signatures.
Applications
When you deploy a smart contract to the Algorand blockchain, it becomes an Application with a unique Application ID. These Applications can be interacted with through special transactions called Application Calls. Applications form the foundation of decentralized applications (dApps) by handling their core on-chain logic.
State Management
Applications can modify state associated with the application as global state or as local state for specific application and account pairs.
On-Chain Access
Applications can access on-chain values, such as account balances, asset configuration parameters, or the latest block time.
Inner Transactions
Applications can execute inner transactions during their execution, allowing one application to call another. This enables composability between applications.
Application Account
Each Application has an Application Account which can hold Algo and Algorand Standard Assets (ASAs), making it useful as an on-chain escrow.
To provide a standard method for exposing an API and encoding/decoding data types from application call transactions, the ABI should be used.
Logic Signatures
Logic Signatures are programs that validate transactions through custom rules and are primarily used for signature delegation. When submitting a transaction with a Logic Signature, the program code is included and evaluated by the Algorand Virtual Machine (AVM). The transaction only proceeds if the program successfully executes - if the program fails, the transaction is rejected.
Specialized Accounts
Logic Signatures can create specialized Algorand accounts that hold Algo or assets. These accounts only release funds when a transaction meets the conditions specified in the program.
Account Delegation
They enable account delegation, where an account owner can define specific transaction rules that allow another account to act on their behalf.
Independent Verification
Each transaction using a Logic Signature is independently verified by an Algorand node using the AVM. These programs have limited access to global variables, temporary scratch space, and the properties of the transaction(s) they are validating.
Writing Smart Contracts
Algorand smart contracts are written in standard Python and TypeScript - known as Algorand Python and Algorand TypeScript in the ecosystem. These are not special variants or supersets, but rather standard code that compiles to TEAL. This means developers can use their existing knowledge, tools, and practices while building smart contracts. The direct compilation to TEAL for the Algorand Virtual Machine (AVM) provides an ideal balance of familiar development experience and blockchain performance.
Algorand TypeScript
import { Contract } from '@algorandfoundation/tealscript';
export class HelloWorld extends Contract {
/**
* @param name The name of the user to greet.
* @returns A greeting message to the user.
*/
hello(name: string): string {
return 'Hello, ' + name;
}
}Algorand Python
from algopy import ARC4Contract, arc4
class HelloWorldContract(ARC4Contract):
@arc4.abimethod
def hello(self, name: arc4.String) -> arc4.String:
return "Hello, " + nameKey Features
Instant Finality
Transactions are final in under 3 seconds with immediate confirmation
Multiple Languages
Write contracts in TEAL, Python, or TypeScript with familiar syntax
Low Cost
Minimal transaction fees for contract execution and deployment
Development Advantages
Familiar Development Experience
Use standard Python and TypeScript syntax, tools, and development practices. No need to learn specialized blockchain languages or frameworks.
Optimized Compilation
Advanced compilers (PuyaPy for Python, PuyaTs for TypeScript) ensure optimal TEAL bytecode generation with performance optimizations.
Seamless Integration
Direct compatibility with AlgoKit typed clients simplifies deployment, testing, and interaction with smart contracts.
