EIPs Explained

ERC-4944 · Stagnant · ERC · 2022-03-25

ERC-4944: Contract with Exactly One Non-fungible Token

An ERC-721 contract that mints exactly one token, so the contract address itself identifies the NFT and can hold its own ERC-20 balance that the NFT owner controls.

What problem does it solve?

In ERC-721 an NFT is identified by the pair (contract address, token ID), and the collection contract is shared by thousands of tokens. A single NFT has no address of its own, so it cannot directly own other assets.

ERC-4944 takes the opposite approach: one contract, one token. Because the contract address now uniquely identifies the NFT, anything sent to that address effectively belongs to the NFT. The authors' motivating idea is an NFT with its own "budget": for example, a digital artwork holding ERC-20 tokens that pay for its own preservation, or an NFT that acts like an autonomous agent owning other assets. It aims to get composability similar to ERC-998 without extra machinery, while staying fully ERC-721 compatible so marketplaces and wallets still work.

How it works

The spec is short and mostly convention:

  • The constructor mints the single token (token ID 0 in the reference code) to the deployer and sets a flag so no further minting is possible.
  • The contract is otherwise a normal ERC-721, so it can be listed, transferred and displayed by existing tools.
  • A token-spending function lets the current NFT owner move ERC-20 tokens that were sent to the contract. Ownership is checked with balanceOf(msg.sender) > 0, so whoever holds the NFT controls the budget, and that control moves with the NFT on transfer.
  • A helper returns the contract's balance of a given ERC-20.

Sample code

Based on the reference implementation, using OpenZeppelin v5:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract SingleNFT is ERC721 {
    using SafeERC20 for IERC20;

    constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {
        _mint(msg.sender, 0); // the one and only token; no public mint exists
    }

    modifier onlyHolder() {
        require(balanceOf(msg.sender) > 0, "not the NFT owner");
        _;
    }

    /// Spend ERC-20 tokens held by this NFT.
    function transferTokens(IERC20 token, address to, uint256 amount) external onlyHolder {
        token.safeTransfer(to, amount);
    }

    function balanceTokens(IERC20 token) external view returns (uint256) {
        return token.balanceOf(address(this));
    }
}

Things to know

  • Status is Stagnant. The spec is informal (no interface ID, few MUSTs), so implementations may differ.
  • Deploying a whole contract per NFT is far more expensive than minting into a shared collection, and the approach does not help existing NFTs.
  • ERC-6551 (token-bound accounts) solves the same "an NFT that owns things" problem differently: it gives any existing ERC-721 token its own smart-contract account, without redeploying.
  • The reference only handles ERC-20. Holding ETH or other NFTs would need extra receive/transfer functions.
  • Whoever holds the NFT controls everything inside it, so selling the NFT hands over its balance too.

#nft #erc-721 #single-token #composable

Details

Authors
Víctor Muñoz (@victormunoz), Josep Lluis de la Rosa (@peplluis7), Andres El-Fakdi (@Bluezfish)
Status
Stagnant
Type
Standards Track / ERC
Created
2022-03-25
Requires

Machine-readable: Markdown · JSON