EIPs Explained

ERC-6147 · Final · ERC · 2022-12-07

ERC-6147: Guard of NFT/SBT, an Extension of ERC-721

An ERC-721 extension that adds a time-limited guard who alone can transfer the NFT while it is set, separating the right to hold a token from the right to move it.

What problem does it solve?

With plain ERC-721, whoever controls the owner's key (or an approved operator) can move the NFT. That makes several common needs awkward:

  • Anti-theft: keeping NFTs safe usually means moving them to a cold wallet, where they are hard to use.
  • Lending: the borrower must lock the NFT in the lending contract and loses the ability to use it while the loan is open.
  • Soulbound tokens: if an SBT holder loses their key there is no standard way to recover the token, and issuers (for example a university issuing diplomas) have no standard way to revoke one.

ERC-6147 splits the "holding right" from the "transfer right" by introducing a new role, the guard, with an expiry time.

How it works

Each token can have a guard address and an expires timestamp. A guard is only valid before expires.

  • No guard (or expired): owner, approved address and operators can set a guard with changeGuard(tokenId, guard, expires). Transfers work like normal ERC-721. guardInfo returns (address(0), 0).
  • Valid guard: the owner, approved address and operators cannot transfer the token and cannot change the guard. Only the guard can:
    • changeGuard to a new guard or expiry,
    • removeGuard to give control back,
    • transfer the token, including transferAndRemove(from, to, tokenId) which transfers and clears the guard in one step.
  • Burning a token deletes its guard. Every change emits UpdateGuardLog.
  • supportsInterface(0xb61d1057) returns true.

The owner keeps ownership (and so any utility tied to ownerOf), while the guard controls movement. Example uses from the spec:

  • Set your own cold wallet as guard: use the NFT from a hot wallet but a stolen hot key cannot move it.
  • Set a lender as guard: keep using the NFT; on default the lender can transfer it.
  • An SBT issuer sets itself as guard at mint: holders cannot transfer, but the issuer can recover or revoke.

Sample code

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

interface IERC6147 {
    event UpdateGuardLog(uint256 indexed tokenId, address indexed newGuard, address oldGuard, uint64 expires);

    function changeGuard(uint256 tokenId, address newGuard, uint64 expires) external;
    function removeGuard(uint256 tokenId) external;
    function transferAndRemove(address from, address to, uint256 tokenId) external;
    function guardInfo(uint256 tokenId) external view returns (address, uint64);
}

A marketplace refusing to list guarded tokens:

function list(address nft, uint256 tokenId, uint256 price) external {
    (address guard, ) = IERC6147(nft).guardInfo(tokenId);
    require(guard == address(0), "token is guarded");
    // ... create listing
}

Checking from ethers v6:

const nft = new Contract(addr, ["function guardInfo(uint256) view returns (address,uint64)"], provider);
const [guard, expires] = await nft.guardInfo(42n);
if (guard !== ZeroAddress) console.log(`guarded until ${new Date(Number(expires) * 1000)}`);

Things to know

  • Status: Final.
  • Choose expires carefully. A short expiry limits the damage if the guard's key is lost (the owner regains control afterwards); a long one gives the guard (for example a lender) a stronger guarantee.
  • While a guard is valid, existing approve / setApprovalForAll permissions are useless. Marketplaces that rely on operator approvals and signed listings should check guardInfo so they do not list tokens that cannot be delivered.
  • The guard can be a contract, which lets you build social recovery, multisig control or lending logic on top.
  • Related NFT extensions include ERC-4907 (separate "user" role for rentals) and ERC-5192 (minimal soulbound locking).

#nft #sbt #erc721 #security #lending

Details

Authors
5660-eth (@5660-eth), Wizard Wang
Status
Final
Type
Standards Track / ERC
Created
2022-12-07
Requires

Machine-readable: Markdown · JSON