EIPs Explained

ERC-4353 · Stagnant · ERC · 2021-10-08

ERC-4353: Interface for Staked Tokens in NFTs

A one-function interface, `stakedAmount(tokenId)`, that lets wallets and marketplaces show how many tokens are staked or locked inside an NFT.

What problem does it solve?

Some NFTs carry value inside them: a creator deposits tokens or ETH when minting, and the holder gets that value back when the NFT is burned. Think of it as an NFT with an escrowed balance attached.

The problem is that this value is invisible. There was no common way for a wallet, marketplace or block explorer to ask "how much is staked in this NFT?", so the information could not be shown to buyers, and every project exposed it (if at all) in its own way.

ERC-4353 defines a single read-only function so any tool can display that number.

How it works

The interface, detectable through ERC-165 (interface ID 0x3a3d855f), is:

interface IERC721Staked {
    function stakedAmount(uint256 tokenId) external view returns (uint256);
}

A wallet or marketplace checks whether an ERC-721 contract supports the interface, then calls stakedAmount(tokenId) to get the current amount of tokens staked in, or bound to, that NFT.

The standard is deliberately agnostic about how tokens get in and out. Its suggested pattern is:

  • Stake at mint: value is deposited when the NFT is created.
  • Withdraw only at burn: no other outbound transfer exists, so the reported amount cannot silently change.

The staked asset can be ETH, ERC-20 tokens, or something derived from them; the function only reports a number.

Sample code

An NFT that locks the ETH sent at mint and returns it to the original minter on burn (simplified from the spec's example, using OpenZeppelin):

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

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract StakedNFT is ERC721, Ownable {
    mapping(uint256 => uint256) private _staked;
    mapping(uint256 => address payable) private _payee;

    constructor() ERC721("Staked NFT", "SNFT") Ownable(msg.sender) {}

    function mint(address payable to, uint256 tokenId) external payable onlyOwner {
        _mint(to, tokenId);
        _staked[tokenId] = msg.value;   // stake at mint
        _payee[tokenId] = to;
    }

    function stakedAmount(uint256 tokenId) external view returns (uint256) {
        return _staked[tokenId];
    }

    function burn(uint256 tokenId) external onlyOwner {
        uint256 amount = _staked[tokenId];
        _staked[tokenId] = 0;
        _burn(tokenId);
        _payee[tokenId].transfer(amount); // withdraw only at burn
    }

    function supportsInterface(bytes4 id) public view override returns (bool) {
        return id == 0x3a3d855f || super.supportsInterface(id);
    }
}

Things to know

  • Status: Stagnant. The proposal has not progressed and is not widely implemented.
  • The number is a claim made by the contract. It is only trustworthy if the contract enforces a locking rule (for example, withdraw only at burn). If tokens can be moved by other paths, stakedAmount may be wrong.
  • Buyers and integrators should read the contract, not just the returned value, before assigning worth to an NFT.
  • A related idea from the other direction is ERC-4987, which lets a contract that holds tokens report who their functional owner is.

#nft #staking #erc721 #interface

Details

Authors
Rex Creed (@aug2uag), Dane Scarborough <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2021-10-08
Requires

Machine-readable: Markdown · JSON