LFelli
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • 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
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
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
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    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: Lucas Felli (@Lfelli), Charles Dehlinger (@Charles.d) type: Financial Application (FA) created: 2022-08-10 date: 2021-28-02 version: 0.7 --- ## 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 * is_operator * get_allowance * get_token_metadata * is_token * events: * transfer_event * balance_update * total_supply_update * operator_update * allowance_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. * By default, transfer of zero amount is allowed but beware of the behavior regarding allowance equals to `0` (or not set at all). 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 or check `%from_`'s balance is enough to transfer `%amount`. #### `approve` ``` (list %approve (pair (address %owner) (address %spender) (nat %token_id) (or (nat %increase) (nat %decrease) ) ) ) ``` This entrypoint allows to increase or decrease the allowance set to `%spender` regarding a token `%owner` and a `%token_id`. The `%spender` can withdraw multiple times from the `%owner`'s balance up to the set value. In case of a decrease below `0`, no error is thrown, the allowance MUST be removed or set to `0`. Beware of the case where anyone can transfer a `0` amount of tokens from anyone else because the default allowance is `0`. 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 approve on behalf of the token owner. Depending on the business use case, the particular implementation of the FA2.1 contract MAY limit allowance updates to a token owner (`owner == SENDER`) or it can be limited to an administrator. #### `export_ticket` ``` (list %export_ticket (pair (or %destination key_hash (contract (list (pair (option address) (ticket (pair nat (option bytes))) ) ) ) ) (list (pair (option %to_ address) (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: * `key_hash`, an operation is emitted for each exported ticket and the `key_hash` MUST be typed as a `(contract (ticket (pair nat (option bytes)))`. This allow tz addresses to receive tickets. * `contract`, only one operation is necessary to transfer the tickets batched in a list. The contract MUST fail with the error mnemonic `"FA2.1_INVALID_DESTINATION"` if the destination can't be correctly typed. For contract receveiving the exported tickets, if needed the parameter `(option %to_ address)` SHOULD be used to associate the ticket to an address. The entrypoint MUST comply with the same policy as the `transfer` entrypoint. The balance of `%destination` and `%to_` and the total supply of MUST remain unchanged. #### `import_ticket` ``` (list %import_ticket (pair (option %to_ address) (list %tickets (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"`. If any of the `(option %to_ address)` is `none`, the entrypoint MUST fail with the error mnemonic `"FA2.1_INVALID_RECIPIENT"`. The total supply MUST remain unchanged. ### Views To let the view caller implements its own error handling logic, it's recommended to not fail 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 or a non-existing token id. #### `get_balance` Returns the number of tokens `%token_id` held for each `%owner` in the `%requests` list. If `%owner` isn't known by the contract or `%token_id` doesn't exixt, the default returned value SHOULD be `0`. ``` view "get_balance" (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. If `%token_id` doesn't exixt, the default returned value SHOULD be `0`. ``` view "get_total_supply" (nat %token_id) (nat %total_supply) ``` #### `is_operator` Returns true if `%operator` is an operator of `%owner` for the token `%token_id`. If `%owner` or `%operator` isn't known by the contract or `%token_id` doesn't exixt, the default returned value SHOULD be `False`. ``` view "is_operator" (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`. If `%owner` or `%spender` isn't known by the contract or `%token_id` doesn't exixt, the default returned value SHOULD be `0`. ``` view "get_allowance" (pair (address %owner) (address %spender) (nat %token_id) ) (nat %allowance) ``` #### `get_token_metadata` Returns the metadata associated to `%token_id`. If `%token_id` doesn't exixt, the default returned value SHOULD be an empty `map %token_info`. ``` view "get_token_metadata" (nat %token_id) (map %token_info string bytes) ``` #### `is_token` Returns `True` if `%token_id` exists and `False` otherwise. ``` view "is_token" (nat %token_id) (bool %token_exist) ``` ### Events To avoid confusion about the order of events, they MUST be emitted before further internal transactions if any. #### `transfer_event` MUST be triggered when a transfer occurs by any mechanism (a call to `transfer` but also custom entrypoints implementing a concept of transfer). The entrypoint `export_ticket` and `import_ticket` SHOULD NOT trigger this event. ``` (pair %transfer_event (address %from_) (address %to_) (nat %token_id) (nat %amount) ) ``` #### `balance_update` MUST be triggered when the balance of a token owner is modified by any mechanism. Only one `balance_update` event is allowed per pair (`%owner`, `%token_id`) per transaction. `int %diff` represents the difference between `nat %new_balance` and the previous value (`new_balance = old_balance + diff`). ``` (pair %balance_update (address %owner) (nat %token_id) (nat %new_balance) (int %diff) ) ``` #### `total_supply_update` MUST be triggered when the total supply of a `%token_id` is modified by any mechanism. `int %diff` represents the difference between `nat %new_total_supply` and the previous value (`new_total_supply = old_total_supply + diff`). So a positive `%diff` is a mint and a negative `%diff` is a burn. The list `(list (pair (%owner) (int %owner_diff)))` MUST contains every addresses affected by the total supply update where `%owner_diff` represents the effect on the `%owner`'s balance. The sum of all the `%owner_diff` may not be equal to `%diff` in the case of a creation or destruction of tickets `(ticket (pair nat bytes))`, in this case the list can even be empty. Only one `total_supply_update` event is allowed per `%token_id` per transaction. ``` (pair %total_supply_update (list (pair (address %owner) (int %owner_diff))) (nat %token_id) (nat %new_total_supply) (int %diff) ) ``` #### `operator_update` MUST be triggered when an operator is updated by any mechanism. ``` (pair %operator_update (address %owner) (address %operator) (nat %token_id) (bool %is_operator) ) ``` `%is_operator` is true if `%operator` has been set as an operator of `owner` and false otherwise. #### `allowance_update` MUST be triggered when a spender's allowance is updated by any mechanism (including when the allowance is consummed by a call to `transfer`). `int %diff` represents the difference between `nat %new_allowance` and the previous value (`new_allowance = old_allowance + diff`). ``` (pair %allowance_update (address %owner) (address %spender) (nat %token_id) (nat %new_allowance) (int %diff) ) ``` #### `token_metadata_update` MUST be triggered when a token metadata is updated by any mechanism, for example mint, burn, reveal, etc. In case of the token is burned the `option %new_metadata (map string bytes)` MUST be `none`. ``` (pair %token_metadata_update (nat %token_id) (option %new_metadata (map string 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_INVALID_RECIPIENT"` | A ticket import failed because one of the `option %to_ address` is `none` | | `"FA2.1_INVALID_DESTINATION"` | A destination contract can't be correctly typed to receive the exported tickets | `"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 |

    Import from clipboard

    Paste your markdown or webpage here...

    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 lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    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 Sign in with Wallet
    Wallet ( )
    Connect another wallet

    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

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    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 and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    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.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        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
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

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

        Syncing

        Push failed

        Push successfully