EIPs Explained

ERC-5700 · Draft · ERC · 2022-09-22

ERC-5700: Bindable Token Interface

A draft interface that lets ERC-721 or ERC-1155 tokens "bind" to an NFT, so they travel with that NFT on transfer until its owner unbinds them.

What problem does it solve?

Sometimes several tokens belong together: a phygital garment NFT plus the music, avatar and digital twin that come with it, or a piece of virtual land with its decorations. Moving such a bundle normally means transferring every token separately, and nothing on-chain records that they belong together.

ERC-5700 defines "bindable" tokens. A bindable ERC-721 or ERC-1155 token can be bound to a specific ERC-721 NFT. Once bound, it is owned by the NFT itself rather than by a wallet, so whenever the NFT changes hands the bound tokens implicitly go with it at no extra cost. The current NFT owner can unbind them at any time to get ordinary, transferable tokens back.

How it works

  • Bind. bind(from, bindAddress, bindId, tokenId) transfers the token from from to the NFT contract at bindAddress and records that it belongs to NFT bindId. It must revert if the target contract is not ERC-721 or the NFT does not exist. A Transfer and a Bind event are emitted.
  • Unbind. unbind(from, to, bindAddress, bindId, tokenId) may only be called by the owner (or an approved operator) of the NFT the token is bound to. Ownership moves to to, with the usual safe-transfer receiver check if to is a contract. Unbind and Transfer events are emitted.
  • Queries. binderOf(tokenId) returns the NFT a token is bound to (zero address if unbound), and boundBalanceOf(bindAddress, bindId) counts how many tokens are bound to an NFT.
  • The ERC-1155 flavour adds amounts and batch variants: batchBind, batchUnbind, boundBalanceOfBatch, and BindBatch / UnbindBatch events.

Both interfaces are detected through ERC-165; the ERC-721 version's interface ID is 0x82a34a7d.

Sample code

Binding an accessory token to a "wardrobe" NFT and later reclaiming it (ERC-721 flavour):

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC721Bindable {
    event Bind(address indexed operator, address indexed from,
        address indexed bindAddress, uint256 bindId, uint256 tokenId);
    event Unbind(address indexed operator, address indexed from, address to,
        address indexed bindAddress, uint256 bindId, uint256 tokenId);

    function bind(address from, address bindAddress, uint256 bindId, uint256 tokenId) external;
    function unbind(address from, address to, address bindAddress, uint256 bindId, uint256 tokenId) external;
    function binderOf(uint256 tokenId) external view returns (address, uint256);
    function boundBalanceOf(address bindAddress, uint256 bindId) external view returns (uint256);
}

contract Example {
    function attach(IERC721Bindable accessory, address wardrobe, uint256 wardrobeId, uint256 hatId) external {
        // caller must own (or be approved for) hatId
        accessory.bind(msg.sender, wardrobe, wardrobeId, hatId);
    }

    function detach(IERC721Bindable accessory, address wardrobe, uint256 wardrobeId, uint256 hatId) external {
        // caller must own (or be approved for) the wardrobe NFT
        accessory.unbind(msg.sender, msg.sender, wardrobe, wardrobeId, hatId);
    }
}

Things to know

  • Status is Draft: the interface may still change and should not be treated as a settled standard.
  • Apps that do not understand ERC-5700 will show bound tokens as owned by the NFT contract address, not by the NFT's owner. The spec calls this out as a known trade-off of the lightweight design.
  • Security hinges on unbinding being restricted to the bound NFT's current owner or operator; review that check carefully in any implementation.
  • The spec text and the interface comment disagree on the ERC-1155 bindable interface ID, so verify it against the reference implementation before relying on it.
  • A different approach to the same "NFT owns things" idea is ERC-6551, which gives each NFT its own smart account; ERC-998 is an older composable-NFT draft.

#nft #bundling #composability #token #draft

Details

Authors
Leeren (@leeren)
Status
Draft
Type
Standards Track / ERC
Created
2022-09-22
Requires

Machine-readable: Markdown · JSON