Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-3589 proposes an ERC-721 token that can hold multiple assets of different types and allow them to be transferred together.

This article translates, summarizes, and explains the original proposal.

Other EIP proposals are covered here.

Overview

ERC-3589 defines an ERC-721 extension called an Assembly Token. An assembly can bundle Ether, ERC-20 tokens, ERC-721 NFTs, and ERC-1155 tokens into a single NFT.

ERC-1155 supports batch transfers of multiple token IDs, but those IDs belong to the same ERC-1155 contract. ERC-3589 instead uses an ERC-721 token ID derived from the asset composition and a salt, allowing assets from different contracts and standards to be assembled together.

The resulting NFT can represent the entire bundle, simplifying batch transfers and swaps. The underlying assets are held by the assembly contract, while transferring the wrapper NFT transfers control over the assembled bundle under the implementation's rules.

Motivation

As NFT art and digital collectibles have become popular, some collectors have found conventional trading workflows cumbersome.

For example, if two collectors want to exchange collections, using a marketplace listing and purchase workflow can involve several operations and significant gas costs.

A trusted intermediary could facilitate the swap, but entrusting both parties' NFTs to a third party introduces custody risk.

ERC-3589 addresses this problem by allowing multiple assets to be bundled before exchanging them. An application can then implement an atomic one-to-one swap between assembly tokens rather than coordinating each underlying asset separately. The standard's first step toward this workflow is the assembly mechanism itself; the actual atomic swap requires separate exchange logic.

Specification

Interface

AssemblyNFTInterface.sol
pragma solidity ^0.8.0;

interface AssemblyNFTInterface {

  event AssemblyAsset(address indexed firstHolder,
                    uint256 indexed tokenId,
                    uint256 salt,
                    address[] addresses,
                    uint256[] numbers);

  /**
  * @dev hash function assigns the combination of assets with salt to bytes32 signature that is also the token id.
  * @param `_salt` prevents hash collision, can be chosen by user input or increasing nonce from contract.
  * @param `_addresses` concat assets addresses, e.g. [ERC-20_address1, ERC-20_address2, ERC-721_address_1, ERC-1155_address_1, ERC-1155_address_2]
  * @param `_numbers` describes how many eth, ERC-20 token addresses length, ERC-721 token addresses length, ERC-1155 token addresses length,
  * ERC-20 token amounts, ERC-721 token ids, ERC-1155 token ids and amounts.
  */
  function hash(uint256 _salt, address[] memory _addresses, uint256[] memory _numbers) external pure returns (uint256 tokenId);

  /// @dev to assemble lossless assets
  /// @param `_to` the receiver of the assembly token
  function mint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external returns(uint256 tokenId);

  /// @dev mint with additional logic that calculates the actual received value for tokens.
  function safeMint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external returns(uint256 tokenId);

  /// @dev burn this token and releases assembled assets
  /// @param `_to` to which address the assets is released
  function burn(address _to, uint256 _tokenId, uint256 _salt, address[] calldata _addresses, uint256[] calldata _numbers) external;

}

AssemblyAsset

js
event AssemblyAsset(address indexed firstHolder, uint256 indexed tokenId, uint256 salt, address[] addresses, uint256[] numbers);

Emitted when an asset bundle has been assembled.

The event records the initial holder, the resulting token ID, and the asset composition. The addresses and numeric values are represented as arrays.

Parameters

  • firstHolder
    • The address of the initial holder of the assembled NFT.
  • tokenId
    • The ERC-721 token ID assigned to the assembly.
  • salt
    • A salt used when deriving the token ID.
  • addresses
    • An array containing the addresses of the underlying asset contracts, including ERC-20, ERC-721, and ERC-1155 contracts.
  • numbers
    • An array containing numeric information such as asset quantities, category counts, and token IDs.

hash

js
function hash(uint256 _salt, address[] memory _addresses, uint256[] memory _numbers) external pure returns (uint256 tokenId);

Computes the token ID from the asset composition and salt.

The function deterministically derives an identifier from the supplied asset information. Identical encoded inputs, including the same salt and ordering, produce the same ID. Distinct salts allow separate assemblies with otherwise identical contents to have different identifiers. Collision resistance depends on the hash function and unambiguous input encoding.

Parameters

  • _salt
    • A salt used to distinguish assemblies. It may be supplied by the user or generated from an incrementing contract nonce.
  • _addresses
    • The addresses of the underlying asset contracts.
  • _numbers
    • Numeric asset information, including Ether amounts, token amounts, and token IDs.

Return value

  • tokenId
    • The resulting assembly identifier, represented as a uint256.

mint

js
function mint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external returns(uint256 tokenId);

Assembles assets and mints an ERC-721 token representing the bundle.

This function assumes that the underlying assets can be transferred without a discrepancy between the requested and received amounts. It returns the newly created token ID.

Parameters

  • _to
    • The recipient of the assembly token.
  • _addresses
    • The addresses of the underlying asset contracts.
  • _numbers
    • An array describing asset quantities, token IDs, and related values.

Return value

  • tokenId
    • The ERC-721 token ID assigned to the bundle.

safeMint

js
function safeMint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external returns(uint256 tokenId);

Assembles assets while accounting for tokens whose transfers may deliver less than the requested amount, such as fee-on-transfer ERC-20 tokens.

The reference implementation measures the actual increase in the contract's ERC-20 balance and uses that value when constructing the assembly. This avoids recording the requested amount when the actual deposit is smaller.

Here, safeMint refers to the assembly's asset accounting. It should not be confused with the usual ERC-721 safe-mint receiver check: the reference implementation invokes _mint, not _safeMint.

Parameters

  • _to
    • The recipient of the assembly token.
  • _addresses
    • The addresses of the underlying asset contracts.
  • _numbers
    • An array describing asset quantities, token IDs, and related values.

Return value

  • tokenId
    • The ERC-721 token ID representing the resulting assembly.

burn

js
function burn(address _to, uint256 _tokenId, uint256 _salt, address[] calldata _addresses, uint256[] calldata _numbers) external;

Disassembles an existing bundle and releases its underlying assets to a specified recipient.

The assembly NFT is burned, and the corresponding assets are transferred out of the contract. In the reference implementation, the supplied salt and asset composition must reproduce the token ID, and the caller must be its owner.

Parameters

  • _to
    • The recipient of the released assets.
  • _tokenId
    • The ERC-721 token ID of the assembly to burn.
  • _salt
    • The salt used when creating the assembly.
  • _addresses
    • The underlying contract addresses used during assembly.
  • _numbers
    • The numeric asset information used during assembly.

Rationale

There are many reasons to group NFTs. A collector might want to hold NFTs depicting football players together as a team. Someone with hundreds of NFTs might want to manage them by category, or trade an entire collection as a single unit rather than its individual items.

ERC-3589 uses ERC-721 as a wrapper because many wallets already support the standard. An Assembly Token can itself be included as an asset in another assembly, enabling nested bundles.

A smart contract can also operate on a single assembly NFT instead of handling numerous assets individually. This can simplify bundle-level sales, swaps, and exchanges between collections, although assembling or disassembling the bundle still requires processing its underlying assets.

The AssemblyAsset event records the types and quantities of assets associated with the assembly. A wallet or indexer can use the token ID to locate the corresponding event and display its contents. The hash-derived token ID alone cannot be reversed to recover those contents.

Compatibility

ERC-3589 is designed to be compatible with ERC-721.

Reference implementation

AssemblyNFT.sol
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "./AssemblyNFTInterface.sol";

abstract contract AssemblyNFT is ERC721, ERC721Holder, ERC1155Holder, AssemblyNFTInterface{
  using SafeERC20 for IERC20;

  function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC1155Receiver) returns (bool) {
        return ERC721.supportsInterface(interfaceId) || ERC1155Receiver.supportsInterface(interfaceId);
  }

  uint256 nonce;

  /**
  * layout of _addresses:
  *     erc20 addresses | erc721 addresses | erc1155 addresses
  * layout of _numbers:
  *     eth | erc20.length | erc721.length | erc1155.length | erc20 amounts | erc721 ids | erc1155 ids | erc1155 amounts
   */

  function hash(uint256 _salt, address[] memory _addresses, uint256[] memory _numbers) public pure override returns (uint256 tokenId){
      bytes32 signature = keccak256(abi.encodePacked(_salt));
      for(uint256 i=0; i< _addresses.length; i++){
        signature = keccak256(abi.encodePacked(signature, _addresses[i]));
      }
      for(uint256 j=0; j<_numbers.length; j++){
        signature = keccak256(abi.encodePacked(signature, _numbers[j]));
      }
      assembly {
        tokenId := signature
      }
  }

  function mint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external override returns(uint256 tokenId){
      require(_to != address(0), "can't mint to address(0)");
      require(msg.value == _numbers[0], "value not match");
      require(_addresses.length == _numbers[1] + _numbers[2] + _numbers[3], "2 array length not match");
      require(_addresses.length == _numbers.length -4 - _numbers[3], "numbers length not match");
      uint256 pointerA; //points to first erc20 address, if there is any
      uint256 pointerB =4; //points to first erc20 amount, if there is any
      for(uint256 i = 0; i< _numbers[1]; i++){
        require(_numbers[pointerB] > 0, "transfer erc20 0 amount");
        IERC20(_addresses[pointerA++]).safeTransferFrom(_msgSender(), address(this), _numbers[pointerB++]);
      }
      for(uint256 j = 0; j< _numbers[2]; j++){
        IERC721(_addresses[pointerA++]).safeTransferFrom(_msgSender(), address(this), _numbers[pointerB++]);
      }
      for(uint256 k =0; k< _numbers[3]; k++){
        IERC1155(_addresses[pointerA++]).safeTransferFrom(_msgSender(), address(this), _numbers[pointerB], _numbers[_numbers[3] + pointerB++], "");
      }
      tokenId = hash(nonce, _addresses, _numbers);
      super._mint(_to, tokenId);
      emit AssemblyAsset(_to, tokenId, nonce, _addresses, _numbers);
      nonce ++;
  }

  function safeMint(address _to, address[] memory _addresses, uint256[] memory _numbers) payable external override returns(uint256 tokenId){
      require(_to != address(0), "can't mint to address(0)");
      require(msg.value == _numbers[0], "value not match");
      require(_addresses.length == _numbers[1] + _numbers[2] + _numbers[3], "2 array length not match");
      require(_addresses.length == _numbers.length -4 - _numbers[3], "numbers length not match");
      uint256 pointerA; //points to first erc20 address, if there is any
      uint256 pointerB =4; //points to first erc20 amount, if there is any
      for(uint256 i = 0; i< _numbers[1]; i++){
        require(_numbers[pointerB] > 0, "transfer erc20 0 amount");
        IERC20 token = IERC20(_addresses[pointerA++]);
        uint256 orgBalance = token.balanceOf(address(this));
        token.safeTransferFrom(_msgSender(), address(this), _numbers[pointerB]);
        _numbers[pointerB++] = token.balanceOf(address(this)) - orgBalance;
      }
      for(uint256 j = 0; j< _numbers[2]; j++){
        IERC721(_addresses[pointerA++]).safeTransferFrom(_msgSender(), address(this), _numbers[pointerB++]);
      }
      for(uint256 k =0; k< _numbers[3]; k++){
        IERC1155(_addresses[pointerA++]).safeTransferFrom(_msgSender(), address(this), _numbers[pointerB], _numbers[_numbers[3] + pointerB++], "");
      }
      tokenId = hash(nonce, _addresses, _numbers);
      super._mint(_to, tokenId);
      emit AssemblyAsset(_to, tokenId, nonce, _addresses, _numbers);
      nonce ++;
  }

  function burn(address _to, uint256 _tokenId, uint256 _salt, address[] calldata _addresses, uint256[] calldata _numbers) override external {
      require(_msgSender() == ownerOf(_tokenId), "not owned");
      require(_tokenId == hash(_salt, _addresses, _numbers));
      super._burn(_tokenId);
      payable(_to).transfer(_numbers[0]);
      uint256 pointerA; //points to first erc20 address, if there is any
      uint256 pointerB =4; //points to first erc20 amount, if there is any
      for(uint256 i = 0; i< _numbers[1]; i++){
        require(_numbers[pointerB] > 0, "transfer erc20 0 amount");
        IERC20(_addresses[pointerA++]).safeTransfer(_to, _numbers[pointerB++]);
      }
      for(uint256 j = 0; j< _numbers[2]; j++){
        IERC721(_addresses[pointerA++]).safeTransferFrom(address(this), _to, _numbers[pointerB++]);
      }
      for(uint256 k =0; k< _numbers[3]; k++){
        IERC1155(_addresses[pointerA++]).safeTransferFrom(address(this), _to, _numbers[pointerB], _numbers[_numbers[3] + pointerB++], "");
      }
  }

}

The original reference implementation is preserved above. It illustrates how the assembly contract takes custody of the underlying assets and releases them when an authorized owner burns the wrapper NFT.

It is not a production security guarantee. Implementations should independently review asset custody, reentrancy, balance accounting, input validation, receiver compatibility, and the ability to redeem every supported asset. The implementation also depends on the OpenZeppelin Contracts version used by the original example.

Security considerations

Users should take care when depositing assets through mint or safeMint.

Some token contracts implement pause mechanisms. If an underlying asset becomes nontransferable after it has been deposited, burning the Assembly Token may fail when the contract attempts to release that asset. Since a failed transaction reverts the operation, a single blocked asset can prevent redemption of the entire bundle.

Platforms using ERC-3589 can mitigate this risk through allowlists of supported tokens or blocklists of known problematic tokens. These controls reduce exposure to incompatible assets but do not guarantee that a supported asset will remain transferable in the future.

Citation

Zhenyu Sun (@Ungigdu), Xinqi Yang (@xinqiyang), "ERC-3589: Assemble assets into NFTs [DRAFT]," Ethereum Improvement Proposals, no. 3589, May 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3589.

Conclusion

ERC-3589 proposes using an ERC-721 NFT to represent a bundle of assets drawn from multiple token standards. Transferring the wrapper can simplify the exchange of entire collections, while burning it releases the underlying assets according to the implementation's redemption rules.

Questions are welcome through Twitter direct messages.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/