Overview | Algorand Developer Portal

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.

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.

Example Code in 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;
  }
}

Example Code in Python

from algopy import ARC4Contract, arc4

class HelloWorldContract(ARC4Contract):
    @arc4.abimethod
    def hello(self, name: arc4.String) -> arc4.String:
        return "Hello, " + name

Key Concepts

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