Skip to content
On this page

Overview

Introduction

FA2 is the Tezos standard for a unified token contract interface.

It caters to a diverse range of token kinds and implementations, including but not limited to fungible tokens and NFTs.

The standards relevant for FA2 are TZIP-12 and TZIP-16. They are functionality equivalent to Ethereum's ERC-20, ERC-721, and ERC-1155.

Library

SmartPy provides a modular FA2 library that can be configured and adapted with custom logic to support a very wide range of needs.

python
import smartpy as sp
from smartpy.templates import fa2_lib as fa2

The library has these main components:

  • Base classes that add the main functionality for a kind of token (NFT, fungible, or single asset)
  • Mixins that add features to the base classes, such as the ability to mint and burn tokens.
  • Transfer policies that control who can transfer tokens
  • Errors, both defined by the standard and added by the library

Resources

The online IDE has templates that you can use to get started with the FA2 library:

Token identification

A token is uniquely identified on the chain by:

  • its contract address and
  • a token id, which is a natural number (sp.nat).

If a contract supports only a single token, the token ID must be 0. Although the contract is responsible for managing and assigning token ids, the FA2 library simplifies this process by automatically incrementing token ids.

Glossary

  • Burn: The process of destroying tokens permanently, reducing the total supply of the tokens in the system. Burning tokens is a common practice to control the circulation and stabilize the value of tokens.
  • ERC-20, ERC-721, and ERC-1155: Equivalent standards for tokens on the Ethereum blockchain. ERC-20 defines a common list of rules for Ethereum tokens to follow, allowing for seamless interaction with other tokens; ERC-721 is the standard for non-fungible Ethereum tokens, and ERC-1155 is a multi-token standard that supports any mix of fungible and non-fungible tokens.
  • FA1.2 and FA2: The two most recent standard for token contracts on Tezos. FA2 is the more recent and flexible standard, supporting both fungible and non-fungible tokens, whereas FA1.2 supports only fungible tokens.
  • Fungible Token: A type of digital token where each unit is interchangeable with any other unit.
  • Ledger: A digital register that tracks the ownership of tokens.
  • Metadata: Supplementary information associated with tokens or contracts which doesn't directly influence the contract's logic.
  • Mint: The process of creating new tokens. In the context of smart contracts, minting is often a function that allows certain addresses to create new tokens in the system.
  • Non-Fungible Token (NFT): A type of digital asset in which each token is completely unique, making them irreplaceable with something else.
  • Token: A digital asset representing a unit of value.
  • TZIP: Tezos Improvement Proposal, a design document providing information or describing a new feature for Tezos or its processes or environment. TZIPs propose and discuss changes and additions to the Tezos protocol.