Alpha preview. Not for production use.
Working anonymously. to save your work permanently.
Reference

ABI & ARC Standards

Understanding the Algorand Application Binary Interface and related standards.

What is the ABI?

The Algorand Application Binary Interface (ABI) defines how to interact with smart contracts in a standardized way. It specifies:

  • How to encode/decode method arguments and return values
  • Method signatures and selectors
  • Type system for contract data

The ABI is defined in ARC-4 and extended by several other standards.

Key ARC Standards

ARC-4 Application Binary Interface (ABI)

The foundational standard defining how to call contract methods, encode parameters, and interpret return values. All ABI methods are identified by a 4-byte selector.

ARC-28 Event Logging

Standard for emitting events from contracts. Events are logged using a specific format that clients can parse and index.

ARC-32 Application Specification (Legacy)

The original specification format (.arc32.json) describing a contract's interface. Superseded by ARC-56.

ARC-56 Extended Application Specification

The current standard (.arc56.json) with full state key definitions, box storage schemas, struct definitions, source maps, and detailed type information. This is what AVM Studio generates by default.

ARC-56 Application Specification

The ARC-56 spec ({Contract}.arc56.json) is a JSON document that fully describes a contract's interface. AVM Studio uses it for:

  • Generating method call forms in the Explorer
  • Decoding state values with proper types
  • Validating method arguments
  • Generating TypeScript client code
  • Providing source maps for debugging

ARC-56 Structure

Counter.arc56.json JSON
1{
2  "name": "Counter",
3  "desc": "A simple counter contract",
4  "methods": [
5    {
6      "name": "increment",
7      "args": [],
8      "returns": { "type": "uint64" },
9      "desc": "Increment the counter and return the new value"
10    },
11    {
12      "name": "getCount",
13      "args": [],
14      "returns": { "type": "uint64" },
15      "readonly": true,
16      "desc": "Get the current count without modifying state"
17    }
18  ],
19  "state": {
20    "schema": {
21      "global": { "ints": 1, "bytes": 0 },
22      "local": { "ints": 0, "bytes": 0 }
23    },
24    "keys": {
25      "global": {
26        "count": {
27          "key": "count",
28          "keyType": "bytes",
29          "valueType": "uint64",
30          "desc": "The current counter value"
31        }
32      }
33    }
34  }
35}
Tip
When you build a contract in AVM Studio, the ARC-56 spec is automatically generated as {ContractName}.arc56.json and included in the build artifacts.

ABI Type System

The ABI defines a comprehensive type system for encoding data:

Basic Types

TypeDescriptionExample
uint6464-bit unsigned integer1000000
uint8 - uint512Unsigned integers (8-512 bits)255
boolBoolean valuetrue
address32-byte Algorand addressABC...XYZ
byteSingle byte0xFF
stringUTF-8 string (variable length)"hello"

Compound Types

TypeDescriptionExample
uint64[]Dynamic array[1, 2, 3]
uint64[3]Fixed-size array[1, 2, 3]
byte[32]Fixed-size byte arrayHash/key bytes
(uint64,address)Tuple[100, "ABC..."]

Transaction Reference Types

TypeDescription
txnAny transaction in the group
payPayment transaction
axferAsset transfer transaction
applApplication call transaction
acfgAsset config transaction

Method Selectors

ABI methods are identified by a 4-byte selector computed from the method signature:

Text
1Method: increment()uint64
2Signature: "increment()uint64"
3Selector: SHA512/256("increment()uint64")[0:4] = 0x1a2b3c4d

When calling a contract, the first application argument contains the method selector.

Note
AVM Studio calculates method selectors automatically. You don't need to compute them manually.

State Schema

The AppSpec defines how much state the contract uses:

Global State

Shared storage accessible by all users. Limited to 64 key-value pairs.

  • ints - Number of uint64 values
  • bytes - Number of byte slice values

Local State

Per-account storage for users who opt in. Limited to 16 key-value pairs per account.

Box Storage

Flexible storage with named boxes up to 32KB each. ARC-56 adds schemas for box definitions.

JSON
1{
2  "state": {
3    "keys": {
4      "box": {
5        "users": {
6          "keyType": "address",
7          "valueType": "(uint64,string)",
8          "prefix": "u_",
9          "desc": "User profile data"
10        }
11      }
12    }
13  }
14}

Events (ARC-28)

Contracts can emit events that are logged on-chain and can be indexed by clients:

JSON
1{
2  "events": [
3    {
4      "name": "Transfer",
5      "args": [
6        { "name": "from", "type": "address" },
7        { "name": "to", "type": "address" },
8        { "name": "amount", "type": "uint64" }
9      ],
10      "desc": "Emitted when tokens are transferred"
11    }
12  ]
13}

Events are emitted via the log opcode with a specific encoding format.

Generated TypeScript Clients

AVM Studio generates TypeScript client code ({Contract}Client.ts) from the ARC-56 spec:

CounterClient.ts TypeScript
1// Auto-generated from Counter.arc56.json
2import { AlgorandClient } from '@algorandfoundation/algokit-utils';
3
4export class CounterClient {
5  async increment(): Promise<bigint> {
6    // Type-safe method call with automatic ABI encoding
7  }
8
9  async getCount(): Promise<bigint> {
10    // Read-only method (uses simulate, no transaction)
11  }
12}

The generated client provides type-safe methods matching the contract's ABI, with automatic encoding/decoding of arguments and return values.

Importing External Contracts

You can import deployed contracts by providing their ARC-56 or ARC-32 specification:

  1. Go to the Explorer
  2. Click Import Contract
  3. Enter the App ID and select the network
  4. Upload the .arc56.json or .arc32.json file
  5. The contract is now available with full ABI support
Tip
Many deployed contracts publish their specification files. Check the contract's documentation or repository for the .arc56.json file.