Skip to content

Overview

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.

  • Applications can modify state associated with the application as global state or as local state for specific application and account pairs.
  • Applications can access on-chain values, such as account balances, asset configuration parameters, or the latest block time.
  • Applications can execute inner transactions during their execution, allowing one application to call another. This enables composability between applications.
  • 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.

Logic Signatures can be used in two ways. First, they 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. Second, they enable account delegation, where an account owner can define specific transaction rules that allow another account to act on their behalf.

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.

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;
}
}

Key Concepts

Understanding these fundamental concepts is essential for developing effective smart contracts on Algorand.