ja
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Tezos ERC-1155 smart contract specification ## Abstract This document describes specification for Tezos ERC-1155 contract adapted from the corresponding specification for [Ethereum](https://eips.ethereum.org/EIPS/eip-1155). Token standards like ERC-20 and ERC-721 require a separate contract to be deployed for each token type or collection. ERC-1155 contract manages multiple token types. A new token can be created and configured without redeploying the contract. Both fungible and non-fungible tokens can be stored in the same smart-contract. ## ERC-1155 overview **Token type** is a specific token represented by its ID. **Owner** - Tezos address which can hold tokens. **Operator** - Tezos address which initiates token transfer operation. **Operator** must be approved to manage all tokens hold by the owner to make a transfer from the owner account. Destination address for the token transfer operation MUST implement `ERC1155TokenReceiver` interface, which MUST be called for transfer/mint transactions. Destination address may reject receiving tokens by generating failure. This is considered a safety feature ("safe transfer") to prevent unrecoverable tokens if sent to an address that does not expect to receive ERC-1155 tokens. ERC-1155 supports both single token transfer and atomic batch transfer of multiple tokens. Administrative operations to create new token types, mint and burn tokens are not part of ERC-1155 specification. ## Difference between Ethereum and Tezos Since Tezos and Michelson differ from Ethereum/Solidity, the following modifications are made: 1. Tezos ERC-1155 does not emit events (a feature not supported by Tezos). 2. Tezos ERC-1155 does not implement ERC-165 `supportsInterface` entry point. 3. Ethereum specification says that if destination transfer address is not a smart contract (Externally Owned Account),then safety check is not performed. Otherwise, if destination contract does not implement `ERC1155TokenReceiver` interface, the transaction should fail. Michelson does not provide API to distinguish between implicit (EOA) and originated addresses since Babylon version. Tezos specification requires that safety check MUST be performed only when target contract implements `ERC1155TokenReceiver` interface. Otherwise, safety check is skipped. 4. Ordering requirements for batch transfers is relaxed. Since Tezos smart contracts are referentially transparent, batch order must be preserved only for invocation of `OnERC1155Received`/`OnERC1155BatchReceived` entry points of `ERC1155TokenReceiver` interface. 5. Optional `ERC1155Metadata_URI` interface is not part of Tezos ERC-1155 specification. ## Specification Specification is given as definition of Michelson entry points defined in [cameligo language](https://ligolang.org). ERC-1155 specification consist of two interfaces: `erc1155` and `erc1155_token_receiver`. ** Smart contracts implementing the ERC-1155 standard protocol MUST implement all of the entry points in the `erc1155` interface.** ** All smart contracts which can be a target destination for the token transfers MUST implement all of the entry points in the `erc1155_token_receiver` interface. ### `erc1155` entry points ```ocaml type token_id = nat type safe_transfer_from_param = { from: address; (* Source address *) to_: address; (* Target address. Target smart contract must implement entry points from `erc1155_receiver` interface *) token_id: token_id; (* ID of the token type *) amount: nat; (* Transfer amount *) data: bytes; (* Additional data with no specified format, MUST be sent unaltered in call to `On_erc1155_received` on `to_` *) } type tx = { token_id: token_id; (* ID of the token type *) amount: nat; (* Transfer amount *) } type safe_batch_transfer_from_param = { from: address; (* Source address *) to_: address; (* Target address. Target smart contract must implement entry points from `erc1155_receiver` interface *) batch: tx list; (* Batch of tokens and their amounts to be transferred *) data: bytes; (* Additional data with no specified format, MUST be sent unaltered in call to `On_erc1155_batch_received` on `to_` *) } type balance_request = { owner: address; (* The address of the token holder *) token_id: token_id; (* ID of the token *) } type balance_of_param = { balance_request: balance_request; balance_view: balance_request * nat -> operation; } type balance_of_batch_param = { balance_request: balance_request list; balance_view: balance_request * nat list -> operation; } type set_approval_for_all_param = { operator: address; (* Address to add or remove from the set of authorized operators for sender *) approved: bool; (* True if the operator is approved, false to revoke approval *) } type is_approved_for_all_request = { owner: address; (* The owner of the tokens *) operator: address; (* Address of authorized operator *) } type is_approved_for_all_param = { is_approved_for_all_request: is_approved_for_all_request; approved_view: is_approved_for_all_request * bool -> operation } (* ERC1155 entry points *) type erc1155 = (* Transfers specified `amount` of an `token_id` from the `from` address to the `to_` address specified (with safety call). Caller must be approved to manage the tokens being transferred out of the `from` account (see "Approval" section of the standard). MUST revert if balance of holder for token `token_id` is lower than the `amount` sent. MUST call `On_erc1155_received` on `to_` and act appropriately (see "Safe Transfer Rules" section of the standard) if `to_` contract implements `erc1155_receiver` interface. Otherwise skips safety check. *) | Safe_transfer_from of safe_transfer_from_param (* Transfers specified `amount`(s) of `token_id`(s) from the `from` address to the `to_` address specified (with safety call). Caller must be approved to manage the tokens being transferred out of the `from` account (see "Approval" section of the standard). MUST revert if any of the balance(s) of the holder(s) for token(s) is lower than the respective amount(s) in `_values` sent to the recipient. MUST call the relevant `erc1155_token_receiver` hook(s) on `to_` and act appropriately (see "Safe Transfer Rules" section of the standard) if `to_` contract implements `erc1155_receiver` interface. Otherwise skips safety check. *) | Safe_batch_transfer_from of safe_batch_transfer_from_param (* Get the balance of an account's tokens. *) | Balance_of of balance_of_param (* Get the balance of multiple account/token pairs *) | Balance_of_batch of balance_of_batch_param (* Enable or disable approval for a third party ("operator") to manage all of the caller's tokens. *) | Set_approval_for_all of set_approval_for_all_param (* Queries the approval status of an operator for a given owner. *) | Is_approved_for_all of is_approved_for_all_param ``` #### `Safe_transfer_from` Rules Transfers specified `amount` of `token_id` from `from` address to `to_` address. Sender MUST be approved to manage the tokens being transferred out of the `from` account or be the same address as `from` address (see "Approval" section of the standard). Otherwise the transaction should fail. The transaction MUST fail if balance of holder for token `token_id` is lower than the `amount` sent. If holder does not hold any tokens of type `token_id`, holder's balance is interpreted as zero. The transaction MUST call entry point `On_erc1155_received` or `On_erc1155_batch_received` of contract `to_` and MUST return call `operation` among other operations it might create. If `to_` contract does not implement entry point `On_erc1155_received`, the transaction MUST skip safety check. `data` argument must be passed unaltered to a receiver hook entry point. A contract MAY skip calling the `On_erc1155_received` hook function if the transfer operation is transferring the token to itself. #### `Safe_batch_transfer_from` Rules Transfers specified amounts between addresses specified in the batch. Transfers should happen atomically: if at least one specified transfer cannot be completed, the whole transaction MUST fail. Sender MUST be approved to manage the tokens being transferred out of the `from` account or be the same address as `from` address (see "Approval" section of the standard). Otherwise the transaction should fail. The transaction MUST fail if any of the balance(s) of the holder for token(s) in the batch is lower than the respective amount(s) sent. If holder does not hold any tokens of type `token_id`, holder's balance is interpreted as zero. The transaction MUST call entry point `On_erc1155_batch_received` or `On_erc1155_received` of contract `to_` and MUST return call `operation` among other operations it might create. If `to_` contract does not implement entry point `On_erc1155_received`, the transaction MUST skip safety check. `data` argument must be passed unaltered to a receiver hook entry point. `On_erc1155_batch_received` and `On_erc1155_received` MAY be called multiple times from the transaction in any combination and the following requirements must be met: * All calls must represent mutually exclusive balance changes. * The set of all calls to `On_erc1155_received` and `On_erc1155_batch_received` describes all balance changes that occurred during the transaction in the order submitted. * A contract MAY skip calling the `On_erc1155_received` hook function if the transfer operation is transferring the token to itself. #### `Balance_of` Get the balance of an account's tokens. `balance_request` parameter has `balance_request.owner` address and `balance_request.token_id`. The entry point parameters are `balance_request` and callback lambda `balance_view` which accepts a pair of `balance_request` and corresponding balance. #### `Balance_of_batch` Get the balance of multiple account/token pairs. Accepts a list of `balance_request`s and callback lambda which accepts a list of pairs of `balance_request` and balance. #### Approval The entry point `Set_approval_for_all` allows an operator to manage one’s entire set of tokens on behalf of the approver. To permit approval of a subset of token IDs, an interface such as [ERC-1761 Scoped Approval Interface](https://eips.ethereum.org/EIPS/eip-1761) is suggested. The counterpart `Is_approved_for_all` provides introspection into any status set by `Set_approval_for_all`. An owner SHOULD be assumed to always be able to operate on their own tokens regardless of approval status, so should SHOULD NOT have to call `Set_approval_for_all` to approve themselves as an operator before they can operate on them. #### Minting/creating and burning/destroying rules A mint/create operation is essentially a specialized transfer and MUST follow safe transfer rules in regard of invoking `On_erc1155_received` and `On_erc1155_batch_received` for the contract which receives minted tokens. ### `erc1155_token_receiver` entry points ```ocaml type on_erc1155_received_param = { operator: address; (* The address which initiated the transfer (i. e. sender) *) from: address option; (* Source address. None for minting operation *) token_id: token_id; (* ID of the token type *) amount: nat; (* Transfer amount *) data: bytes; (* Additional data with no specified format *) } type on_erc1155_batch_received_param = { operator: address; (* The address which initiated the transfer (i. e. sender) *) from: address option; (* Source address. None for minting operation *) batch: tx list; (* Batch of tokens and their amounts which are transferred *) data: bytes; (* Additional data with no specified format *) } (* ERC1155TokenReceiver entry points *) type erc1155_token_receiver = (* Handle the receipt of a single ERC1155 token type. An ERC1155-compliant smart contract MUST call this function on the token recipient contract from a `Safe_transfer_from`. MUST revert if it rejects the transfer. *) | On_erc1155_received of on_erc1155_received_param (* Handle the receipt of multiple ERC1155 token types. An ERC1155-compliant smart contract MUST call this function on the token recipient contract from a `Safe_batch_transfer_from`. MUST revert if it rejects the transfer(s). *) | On_erc1155_batch_received of on_erc1155_batch_received_param ``` #### `erc1155_token_receiver` Rules If an implementation specific API function is used to transfer ERC-1155 token(s) to a contract, the `Safe_transfer_from`or `Safe_batch_transfer_from` (as appropriate) rules MUST still be followed and the receiver MUST implement the `erc1155_token_receiver` interface. Only non-standard transfer functions MAY allow tokens to be sent to a recipient contract that does NOT implement the necessary `erc1155_token_receiver` hook functions.

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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