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.

This article examines ERC-7066, a proposed interface for locking ERC-721 NFTs.

This article translates, summarizes, and expands on the following specification.

More ERC explainers:

Overview

ERC-7066 extends ERC-721 with NFT locking functionality.

For an introduction to ERC-721, see:

https://chaldene.net/erc721

Locking by the owner

An NFT owner can lock a token and designate an EOA or contract account as its locker. The designated locker has authority to unlock it.

Approval for a tokenId

An owner can approve another address for a particular token ID. The approved address can lock the token while that approval remains valid.

Locking by an approved address

An approved address can lock the NFT and designate itself as the locker.

Resetting permissions on transfer

When an NFT is transferred, its existing locking and approval information is reset, subject to the behavior of operations that establish a new lock.

This extension allows applications to restrict transfers and manage NFTs under defined conditions. Owners gain additional control over asset movement and can reduce the risk of unauthorized transfers.

Motivation

ERC-721 has supported substantial growth in NFT markets, but accessing secondary liquidity while keeping NFTs in their owners' wallets remains challenging. Some existing solutions require owners to transfer NFTs into project-controlled contracts, introducing several concerns.

Loss of utility

Transferring an NFT into escrow removes it from the owner's direct control and can prevent the owner from using its associated utility.

Limited composability

Liquidity could improve if owners could combine financial services such as loans and rentals. Existing arrangements do not always support such combinations.

Smart contract vulnerabilities

Bugs or vulnerabilities in custody contracts may lead to NFT losses or theft.

The proposal introduces native locking within an ERC-721 contract. Instead of transferring an NFT into escrow, an owner can keep it in a wallet while restricting transfers. Other utility can remain available, depending on the application.

For example, an NFT used as collateral could remain in its owner's wallet, allowing continued access to an associated Discord server or play-to-earn game. The intended analogy is a mortgaged property whose owner can continue living in it or renting it out while it serves as collateral.

Lockable NFTs have several potential use cases.

NFT-backed loans

Conventional NFT lending may require depositing collateral in the lending protocol's contract. Native locking can allow a loan to be secured while the NFT remains in its owner's wallet and retains compatible utility.

NFT rentals without collateral

A rental application can let a borrower use an NFT for a fee while preventing unauthorized transfers. Returning the NFT at the end of the rental period requires the application or locker contract to implement the appropriate conditions; the locking interface alone does not automate return or guarantee safety.

Buy Now Pay Later (BNPL)

A buyer could receive and use a locked NFT before completing installment payments. Transfer restrictions can prevent resale until payment obligations are satisfied. An application can establish conditions for returning the NFT to the seller if payments are not completed.

Composability

Combining financial tools could increase the utility of an NFT. For example, an application might support using an NFT as loan collateral while renting its utility, provided the respective protocols and permissions are compatible.

Initial sales

A buyer could make a partial payment for an NFT and complete payment later if satisfied with the collection's progress.

Soulbound tokens

An organization could mint an NFT, designate a locker, and deliver it to a user with transfer restrictions.

Security

Owners could use an NFT in a hot wallet such as MetaMask while assigning unlock authority to a separately secured cold wallet. Compromise of the hot wallet alone would not necessarily permit a transfer of the locked NFT, provided the locking and approval logic is correctly implemented.

The proposal takes a distinct approach to NFT locking.

Minimal implementation

The interface keeps locking and unlocking functionality small. Conditions such as time limits, repayment, and expiration can be implemented by smart contracts acting as lockers instead of being embedded in the core interface.

Separating the locker and approved address roles

Locking authority and transfer approval are distinct. The designated locker can unlock the token, while approval governs permitted transfers. This separation supports rentals, lending, and BNPL arrangements.

It also allows a token to remain locked without granting a third party the ability to reclaim it, while retaining an explicitly designated unlock mechanism.

Implementing transferAndLock

The transferAndLock function combines a transfer with locking and optionally grants approval. This supports arrangements where the caller needs to retain a conditional right to reclaim an NFT after transferring it.

Extending ERC-721

The proposed extension provides a primitive for NFT finance applications including staking, lending, and rentals. It aims to improve asset management and encourage broader participation in NFT ecosystems.

Specification

Overview

The proposal defines a common way for ERC-721 contracts to lock and unlock NFTs.

Locking a token

An owner can call lock(uint256 tokenId, address _locker) to lock a token and specify the address authorized to unlock it.

An owner or approved address can also call lock(uint256 tokenId), which assigns msg.sender as the locker.

Unlocking a token

The designated locker can call unlock. The operation clears the locker information by setting it to address(0).

Checking the locker

The lockerOf function returns the address authorized to unlock a locked token, or address(0) if the token is not locked.

Restrictions

Locking an already locked token or unlocking an unlocked token must fail.

ERC-721 approval and transfer operations are restricted while a token is locked. An exception applies when the caller is both approved and the locker. When a transfer takes place, existing locker and approval information is cleared.

Transferring and locking a token

The transferAndLock function combines transfer and locking and can grant the locker approval. It is useful when a conditional reclamation right is required after transfer.

Interface

javascript
// SPDX-License-Identifier: CC0-1.0

pragma solidity >=0.7.0 <0.9.0;

/// @title Lockable Extension for ERC721
/// @dev Interface for the Lockable extension
/// @author StreamNFT 

interface IERC7066{

    /**
     * @dev Emitted when tokenId is locked
     */
    event Lock (uint256 indexed tokenId, address _locker);

    /**
     * @dev Emitted when tokenId is unlocked
     */
    event Unlock (uint256 indexed tokenId);

    /**
     * @dev Lock the tokenId if msg.sender is owner or approved and set locker to msg.sender
     */
    function lock(uint256 tokenId) external;

    /**
     * @dev Lock the tokenId if msg.sender is owner and set locker to _locker
     */
    function lock(uint256 tokenId, address _locker) external;

    /**
     * @dev Unlocks the tokenId if msg.sender is locker
     */
    function unlock(uint256 tokenId) external;

    /**
     * @dev Tranfer and lock the token if the msg.sender is owner or approved. 
     *      Lock the token and set locker to caller
     *      Optionally approve caller if bool setApprove flag is true
     */
    function transferAndLock(uint256 tokenId, address from, address to, bool setApprove) external;

    /**
     * @dev Returns the wallet, that is stated as unlocking wallet for the tokenId.
     *      If address(0) returned, that means token is not locked. Any other result means token is locked.
     */
    function lockerOf(uint256 tokenId) external view returns (address);
}

Events


Lock

javascript
event Lock (uint256 indexed tokenId, address _locker);

Overview

Emitted when a token is locked.

Details

The event records the locking of the specified token ID so external observers can track the operation.

Parameters

  • uint256 indexed tokenId
    • The ID of the locked token.
  • address _locker
    • The designated locker address.

Unlock

javascript
event Unlock (uint256 indexed tokenId);

Overview

Emitted when a token is unlocked.

Details

The event allows external observers to track when the specified token's lock is removed.

Parameters

  • uint256 indexed tokenId
    • The ID of the unlocked token.

Functions


lock

javascript
function lock(uint256 tokenId) external;

Overview

Locks a token.

Details

If msg.sender owns the token or is approved, the function locks the specified token and sets the caller as its locker.

Parameters

  • uint256 tokenId
    • The ID of the token to lock.

lock

javascript
function lock(uint256 tokenId, address _locker) external;

Overview

Locks a token with a designated locker address.

Details

Only the token owner can call this overload. It locks the token and assigns _locker as the locker.

Parameters

  • uint256 tokenId
    • The ID of the token to lock.
  • address _locker
    • The address designated as locker.

unlock

javascript
function unlock(uint256 tokenId) external;

Overview

Unlocks a token.

Details

Only the designated locker can unlock the specified token.

Parameters

  • uint256 tokenId
    • The ID of the token to unlock.

transferAndLock

javascript
function transferAndLock(uint256 tokenId, address from, address to, bool setApprove) external;

Overview

Transfers and locks a token.

Details

If the caller is the owner or an approved address, this operation transfers the token to the recipient and locks it. According to the interface documentation, the caller becomes the locker, rather than the recipient. When setApprove is true, the caller also receives approval.

Parameters

  • uint256 tokenId
    • The ID of the token to transfer and lock.
  • address from
    • The address transferring the token.
  • address to
    • The recipient address.
  • bool setApprove
    • Whether to grant approval to the caller.

lockerOf

javascript
function lockerOf(uint256 tokenId) external view returns (address);

Overview

Returns the token's locker address.

Details

Returns the locker for the specified token ID, or address(0) when the token is unlocked.

Parameters

  • uint256 tokenId
    • The ID of the token to query.

Returns

  • address
    • The locker address, or address(0) if the token is unlocked.

Additional explanation

The proposal concerns NFT locking and unlocking within ERC-721 contracts.

Processing an unlock

When a token is unlocked, locker[tokenId] is set to address(0), clearing the mapping entry. The contract can use this value to determine whether the token is currently locked.

The transferAndLock function

The interface exposes transferAndLock(uint256 tokenId, address from, address to, bool setApprove), allowing a token to be transferred and locked in a single operation.

When setApprove is true, approval is granted to the caller acting as locker. This can support a conditional reclamation mechanism, with the applicable conditions defined by the locker contract.

The recipient owns the token, but its ability to transfer the token is restricted while the lock is active.

The proposal therefore enables more flexible management of ERC-721 tokens and arrangements involving conditional transfer rights.

Backward compatibility

The proposal extends ERC-721. An existing upgradeable ERC-721 contract may be able to introduce native locking through an appropriate upgrade, subject to storage compatibility and other upgrade requirements.

This can support additional financial and asset-management applications.

For more information about upgradeable contracts, see:

Understanding Smart Contract Upgrades

https://chaldene.net/upgradable-contracts

Tests

Test code is available here.

https://eips.ethereum.org/assets/eip-7066/test/test.js

Reference implementation

The reference interface is available here.

https://eips.ethereum.org/assets/eip-7066/IERC7066.sol

The reference contract is available here.

https://eips.ethereum.org/assets/eip-7066/ERC7066.sol

Security considerations

Handling locked tokens

Approval and transfer operations are generally restricted once a token is locked. The specified exceptions must be enforced correctly.

When the locker is also approved

If the locker is also approved to transfer the token, the applicable exception can permit a transfer even while the token is locked.

Permanent locking risk

An inaccessible locker account or an unsuitable contract address may leave a token permanently locked. Developers should carefully consider locker selection and recovery arrangements.

MEV considerations

The original article argues that locking and unlocking are limited to authorized parties, reducing some opportunities for MEV. This restriction does not eliminate all transaction-ordering risks; applications should evaluate their own workflows.

Native locking offers more control over NFT management, but its authorization and state transitions require careful implementation.

Citation

https://eips.ethereum.org/assets/eip-7066/ERC7066.sol

Conclusion

ERC-7066 proposes an interface for locking ERC-721 NFTs and controlling who can unlock them.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

I also publish material on the following platforms.

https://chaldene.net/