HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
      • Create new note
      • Create a note from template
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tzip: 0xx title: FA2.1 status: Draft author: type: Financial Application (FA) created: 2022-08-10 date: 2022-09-26 version: 0.3 --- ## Summary TZIP-0xx proposes FA2.1 as an extension of the FA2 standard introduced in [TZIP-012](https://tzip.tezosagora.org/proposal/tzip-12/). FA2.1 adds support for on-chain views, tickets, events, and a finite allowance mechanism similar to FA1.2. ## Abstract The goal of the FA2.1 extension is to include new protocol features while remaining fully compatible with current applications that rely on the FA2 standard. **Events** are a means to solve discoverability problems encountered by indexers, i.e. to know when a token is transferred especially outside the specified transfer entrypoint (mint, burn, etc…). **On-chain views** are a means for smart contracts to share information easily. Callback views are kept for compatibility with already deployed contracts. **Tickets** are a way to materialize tokens outside of smart contracts. They can be transferred without calling the creator contract and affecting its status. Tezos rollups rely on tickets for representing Layer 1 assets on Layer 2. Additionally, **finite allowance**, enabling a user to grant permission to spend a fixed amount of tokens, is introduced (based on the FA1.2 scheme). ## General The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt). FA2.1 MUST comply with the same rules defined by FA2 standard: - Token type is uniquely identified on the chain by a pair composed of the token contract address and token ID, a natural number (`nat`). If the underlying contract implementation supports only a single token type (e.g. ERC-20-like contract), the token ID MUST be `0n`. In cases where multiple token types are supported within the same FA2.1 token contract (e. g. ERC-1155-like contract), the contract is fully responsible for assigning and managing token IDs. - The FA2.1 batch entrypoints accept a list (batch) of parameters describing a single operation or a query. The batch MUST NOT be reordered or deduplicated and MUST be processed in the same order it is received. - An empty batch is a valid input and MUST be processed as a non-empty one. For example, an empty transfer batch will not affect token balances, but applicable transfer core behavior and permission policy MUST be applied. - If the underlying contract implementation supports only a single token type, the batch may contain zero or multiple entries where token ID is a fixed `0n` value. Likewise, if multiple token types are supported, the batch may contain zero or more entries and there may be duplicate token IDs. ## Extension specification Token contracts implementing the FA2.1 standard MUST follow this interface: * entrypoints: * balance_of (for backwards compatibility with FA2) * update_operators (for backwards compatibility with FA2) * transfer * approve * export_ticket * import_ticket * views: * get_balance * get_total_supply * get_all_tokens * is_operator * get_allowance * get_token_metadata * events: * transfer_event * operator_update * approval_update * token_metadata_update The FA2 entrypoints `balance_of` and `update_operators` should be deprecated at some point, but many applications rely on them so they MUST be implemented for backwards compatibility. In some specific use cases, `export_ticket` and `import_ticket` may cause conflicts with the transfer policy. For this reason, one can simply throw an "FA2.1_TICKETS_UNSUPPORTED" error without implementing the logic of both entrypoints. This standard relies on a specific type of ticket: `(pair nat (option bytes))` to represent assets. Be cautious to not reuse this type if you implement another custom ticket functionnality. ### Entrypoint semantics #### `transfer` The core behavior is the same as for FA2 with additional rules regarding allowances: * To avoid conflicts between `approve` and `update_operators`, the operator's rights take precedence over those of the spender. * If the allowance of the sender falls under zero, the transfer MUST fail with the `"FA2.1_INSUFFICIENT_ALLOWANCE"` error message. * Transfer of zero amount is allowed but in the case of allowance, if no allowance is set (or is equal to zero), the transfer MUST fail. In the case of a self transfer (`%from_ == %to_`), make sure to not allow one to transfer more than they own, i.e. do not update `%to_`'s balance before `%from_`'s balance. #### `approve` ``` (list %approve (pair (address %owner) (address %spender) (nat %token_id) (or (nat %increase) (nat %decrease) ) ) ) ``` This entrypoint allows a token owner to increase or decrease the allowance set to `spender`. The `spender` can withdraw multiple times from the `owner`'s balance up to the value set by `owner`. In case of a decrease below zero, no error is thrown, the allowance MUST be removed. Each call of `transfer` and `export_ticket` entrypoints decreases the allowance amount by the transferred amount of tokens, unless the transfer is called with `from_` being equal to sender or with `from_` being an operator on behalf of the sender. The standard does not specify who is permitted to update spenders on behalf of the token owner. Depending on the business use case, the particular implementation of the FA2.1 contract MAY limit operator updates to a token owner (`owner == SENDER`) or it can be limited to an administrator. #### `export_ticket` ``` (list %export_ticket (pair (or %destination (contract (ticket (pair nat (option bytes)))) (contract (list (ticket (pair nat (option bytes))))) ) (list %tickets_to_export (pair (address %from_) (nat %token_id) (nat %amount) ) ) ) ) ``` The ticket id MUST be a pair containing the `token_id` and any additional information (a timestamp for example) as an `option bytes`. The ticket value MUST be the `amount`. In the case of the `destination` being a: * `(contract (ticket (pair nat (option bytes))))`, an operation is emitted for each exported ticket. * `(contract (list (ticket (pair nat (option bytes)))))`, only one operation is necessary to transfer the tickets batched in a list. The destination SHOULD be a contract able to manage tickets. The entrypoint MUST comply with the same policy as the `transfer` entrypoint. The balance of `%destination` and the total supply MUST remain unchanged. #### `import_ticket` ``` (list %import_ticket (pair (address %to_) (list %tickets_to_import (ticket (pair nat (option bytes))) ) ) ) ``` The nat value of the ticket id of type `(pair nat (option bytes))` represents the `token_id` and the ticket value represents the amount to be credited to the `to_` address for the corresponding `token_id`. The ticket MUST be destroyed upon import. If the ticket has not been created by the contract in which it is imported (`ticketer != SELF_ADDRESS`), the entrypoint MUST fail with the error mnemonic "FA2.1_INVALID_TICKET". The total supply MUST remain unchanged. ### Views We recommend to not throw an error inside a view but rather responding with a meaningful default value to let the callers choose their actions. For example, returning 0 when trying to get the balance of a non-existing wallet. #### `get_balance` Returns the number of tokens `%token_id` held for each `%owner` in the `%requests` list. ``` view "get_balance" (list %requests (pair (address %owner) (nat %token_id) ) ) (list (pair (address %owner) (nat %token_id) (nat %balance) ) ) ``` #### `get_total_supply` Returns the total supply of `token_id`. The total supply accounts for the number of tokens stored by the contract and the ones exported in tickets. i.e., exporting or importing tickets MUST not change the total supply. ``` view "get_total_supply" (list %requests (nat %token_id)) (list (pair (nat %token_id) (nat %total_supply) ) ) ``` #### `get_all_tokens` Has a unit parameter and returns the list of all the token IDs, (list nat), known to the contract. ``` view "get_all_tokens" unit (list (nat %token_id)) ``` #### `is_operator` Returns true if `%operator` is an operator of `%owner` for the token `%token_id` for each triplet in the `%requests` list. ``` view "is_operator" (list %requests (pair (address %owner) (address %operator) (nat %token_id) ) ) (list (pair (address %owner) (address %operator) (nat %token_id) (bool %is_operator) ) ) ``` #### `get_allowance` Returns the number of tokens `%token_id` allowed by `%owner` for `%spender` for each triplet in the `%requests` list. ``` view "get_allowance" (list %requests (pair (address %owner) (address %spender) (nat %token_id) ) ) (list (pair (address %owner) (address %spender) (nat %token_id) (nat %allowance) ) ) ``` #### `get_token_metadata` Returns the metadata aasociated to each `%token_id` in the `%requests` list. ``` view "get_token_metadata" (list %requests (nat %token_id) ) (list (pair (nat %token_id) (bytes %token_metadata) ) ) ``` ### Events #### `transfer_event` MUST be triggered when a balance is updated by any mechanism. `%sender` is the sender of the transaction (`SENDER` in Michelson). In case of a ticket export or any burn-like mechanism, the `option %to_ address` MUST be `none`. In case of a ticket import or any mint-like mechanism, the `option %from_ address` MUST be `none`. The case where both option are `none` should be considered as invalid. ``` (pair %transfer_event (address %sender) (list %transfer (pair (option %from_ address) (list %txs (pair (option %to_ address) (nat %token_id) (nat %amount) ) ) ) ) ) ``` #### `operator_update` MUST be triggered when an operator is updated by any mechanism. ``` (pair %operator_update (address %sender) (list %updates (pair (address %owner) (address %operator) (nat %token_id) (bool %is_operator) ) ) ) ``` `%is_operator` is true if `%operator` has been set as an operator by `owner` and false otherwise. #### `approval_update` MUST be triggered when a spender's allowance is updated by any mechanism. ``` (pair %approval_update (address %sender) (list %updates (pair (address %owner) (address %spender) (nat %token_id) (nat %new_value) (nat %old_value) ) ) ) ``` #### `token_metadata_update` MUST be triggered when a token metadat is updated by any mechanism, for example mint, burn, reveal, etc. In case of the token is burned the `option %new_value bytes` MUST be `none`. ``` (pair %token_metadata_update (address %sender) (list %updates (pair (nat %token_id) (option %new_value bytes) ) ) ) ``` ### Error Handling Following FA2 pattern: | Error mnemonic | Description | | :------------------------------- | :---------------------------------------------------------------------------------------------------- | | `"FA2.1_INVALID_TICKET"` | A ticket import failed because one of the ticket doesn't belong to the contract (`ticketer != SELF_ADDRESS`) | | `"FA2.1_TICKETS_UNSUPPORTED"` | Ticket export/import isn't supported | | `"FA2.1_INSUFFICIENT_ALLOWANCE"` | A token spender does not have sufficient allowance to transfer tokens from owner's account | ### Contract metadata Following the [TZIP-16](https://tzip.tezosagora.org/proposal/tzip-16/) about smart contract metadata, a new field is reserved but optional: - `"NFT only"` (optional, default: false): if the contract manages only NFTs, this flag SHOULD be set to `true` then the contract MUST NOT allow a total supply greater than 1 for any `token_id`.

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully