EIPs Explained

ERC-7066 · Final · ERC · 2023-05-25

ERC-7066: Lockable Extension for ERC-721

An ERC-721 extension that lets an NFT be locked in its owner's wallet with a designated locker address that alone can unlock it, enabling loans, rentals and buy-now-pay-later without escrow.

What problem does it solve?

NFT lending, renting and staking protocols usually take the NFT into escrow. The owner loses its utility (Discord access, in-game use) while it sits in the protocol's contract, and the asset is exposed to bugs in that contract.

ERC-7066 adds native locking: the NFT stays in the owner's wallet but cannot be sold, transferred or newly approved until a designated locker unlocks it. The owner keeps using it; the counterparty keeps security.

How it works

The interface:

Function Who Effect
lock(tokenId) owner or approved Lock, with msg.sender as locker
lock(tokenId, locker) owner Lock, with a chosen locker address
unlock(tokenId) locker Clear the locker (back to address(0))
transferAndLock(tokenId, from, to, setApprove) owner or approved Transfer, lock at the receiver with the caller as locker, optionally also approve the caller
lockerOf(tokenId) anyone Locker address, or address(0) if unlocked

Events Lock(tokenId, locker) and Unlock(tokenId) record changes.

Rules while locked:

  • lock reverts if already locked; unlock reverts if not locked.
  • ERC-721 approve reverts.
  • Any ownership transfer reverts, unless msg.sender is both the locker and the approved address. This is how a lender or rental contract can reclaim the token.
  • After any transfer, both locker and approval are cleared.

Separating "locker" from "approved" gives two patterns: a lender that is both can seize collateral on default; a locker that is not approved can only unlock (useful for soulbound-style tokens or locking against your own cold wallet as a safety measure).

Sample code

Buy-now-pay-later style flow (ethers v6). The seller contract transfers the NFT to the buyer, locked, and keeps approval so it can reclaim on default:

import { Contract } from "ethers";

const nft = new Contract(nftAddr, [
  "function transferAndLock(uint256 tokenId, address from, address to, bool setApprove)",
  "function lockerOf(uint256 tokenId) view returns (address)",
  "function unlock(uint256 tokenId)",
], sellerSigner);

await (await nft.transferAndLock(42n, seller, buyer, true)).wait();
console.log("locker:", await nft.lockerOf(42n)); // seller

// later, once all instalments are paid:
await (await nft.unlock(42n)).wait();

In Solidity, the transfer guard follows this shape:

function _beforeTransfer(uint256 tokenId) internal view {
    address lk = lockerOf(tokenId);
    if (lk != address(0)) {
        require(msg.sender == lk && getApproved(tokenId) == msg.sender, "locked");
    }
}

Things to know

  • Status is Final.
  • Locking to an inaccessible account or an unverified contract can lock the token permanently. Double-check the locker address.
  • A locked token cannot be listed or approved, so marketplaces should check lockerOf before showing it as for sale.
  • Time-based unlocks are not built in; the spec expects them to be implemented in the locker contract.
  • Upgradeable ERC-721 contracts can adopt it; immutable ones cannot without redeploying.
  • Related approaches: ERC-6982 (lock status signalling), ERC-5192 (soulbound lock flag) and ERC-4907 (rental via a user role rather than locking).

#nft #lockable #nftfi #lending #rental

Details

Authors
Piyush Chittara (@piyush-chittara), StreamNFT (@streamnft-tech), Srinivas Joshi (@SrinivasJoshi)
Status
Final
Type
Standards Track / ERC
Created
2023-05-25
Requires

Machine-readable: Markdown · JSON