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.

ERC-7721 proposes a locking mechanism that restricts transfers of ERC-1155 NFTs by token ID while allowing owners to retain them in their wallets.

This article explains the proposal with additional context and examples.

You can find my other articles on EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs here.

Overview

ERC-7721 is an extension to ERC-1155 that adds locking and unlocking functionality. It is particularly relevant to individual tokenId values that represent NFTs.

For more on ERC-1155, see the following article.

[ERC-1155] An Introduction to ERC-1155

While a quantity of a particular token ID is locked, ordinary sales and transfers of that locked quantity are restricted. Other properties of the NFT, such as its use in a game or as a membership pass, can remain available because the owner still holds the token in their wallet.

The mechanism revolves around three permissions and state-management rules.

  • The owner (owner) can lock an NFT.
  • An address called a locker can be designated to hold unlocking authority.
  • Associated locking permissions and approvals are cleared (purge) when the relevant tokens are transferred, so stale permissions do not follow the assets.

The following terminology is useful.

Term Description
EOA An ordinary externally owned account controlled by a private key, such as an account in MetaMask.
Contract address An address associated with a smart contract that can execute according to its code.
locker The address authorized to unlock the quantity of an NFT that it has locked. It may be an EOA or a contract.
approval A mechanism through which an owner permits another address to operate tokens, based on the approval concept in ERC-1155.
tokenId An identifier distinguishing a token type in ERC-1155. Multiple token types may exist within the same contract.
purge Clearing associated permissions, such as locking and approval rights, when tokens are transferred so the previous owner's settings do not carry over.

The distinguishing feature of ERC-7721 is that transfers can be restricted without sacrificing self-custody. Self-custody here means keeping the NFT in the owner's own wallet rather than transferring it to an escrow contract controlled by a third party.

A designated locker can hold unlocking authority. For example, an owner can keep an NFT in a frequently used hot wallet while assigning unlocking authority to a cold wallet. This may reduce the risk of theft while allowing the NFT's utility to remain available.

Permissions for locking and unlocking

ERC-7721 separates locking authority from unlocking authority.

When an owner locks an NFT, they designate a locker. Only the locker can unlock the quantity locked under its authority. The owner can therefore delegate unlocking authority to another address even when initiating the lock personally. The owner can also designate themselves as the locker.

Owners can grant approvals for a particular tokenId. Approved addresses can use their authorization to lock assets and can designate themselves as lockers when doing so. This allows parties other than the owner to initiate a lock for use cases such as rentals and lending.

Locking and approval rights are cleared as applicable when tokens are transferred. This prevents settings made by a previous owner or third party from being inherited by the new owner.

What withdrawing from locked tokens means

The proposal's abstract refers to approved users being able to withdraw a predefined amount from locked tokens. Here, withdrawal is less like physically taking part of a token out of a safe and more like permitting operations on locked tokens subject to a particular tokenId and quantity (amount).

ERC-1155 allows an account to hold multiple units of the same tokenId. Although an NFT commonly uses a quantity of one (amount = 1), the standard itself supports quantities. The design therefore accounts for control at both the token-ID and quantity levels.

Motivation

The adoption of ERC-1155 has increased demand for NFTs, but NFT markets face the problem of limited secondary liquidity. In this context, secondary liquidity means more than whether an NFT can be sold. It also concerns whether NFTs held in owners' wallets can be put to financial use rather than remaining idle.

Projects already exist to improve NFT liquidity, but many require users to transfer their NFTs to a project-controlled contract for custody. This introduces the following limitations and risks.

Problem 1: Loss of utility

Moving an NFT into escrow removes it from the owner's wallet. As a result, features that rely on the owner holding the NFT may become unavailable.

For example, if Discord authentication or use of a game item depends on the wallet holding a particular NFT, transferring it into escrow can remove access to those features. Using an NFT financially by depositing it in a contract can therefore diminish its practical value as an NFT.

Problem 2: Limited composability

Composability means that components can be combined and used together. In DeFi, for example, users commonly borrow against collateral and deploy the borrowed assets in another protocol.

When NFTs are deposited into escrow-based systems, however, using them for multiple purposes at the same time becomes difficult. Market efficiency could improve if NFT owners could combine loans, rentals, and other financial tools, but mandatory custody transfers make this harder.

Problem 3: Smart contract vulnerability risks

If a contract that holds deposited NFTs contains a bug or vulnerability, the NFTs may be lost or stolen. Transferring NFTs into an external contract increases the attack surface.

These three problems can negatively affect the user experience (UX). ERC-7721 aims to address them through a native locking mechanism that leaves NFTs in their owners' wallets instead of requiring transfers to external custody contracts.

Preserving utility while an NFT is locked

Under ERC-7721, the lock restricts transfers. The NFT itself remains in the owner's wallet, so its utility can generally be preserved. An NFT may continue to serve as a membership pass or as equipment in a game while being used as collateral.

The idea resembles real estate: someone can continue living in their home after using it as collateral for a loan. Similarly, an NFT owner should be able to use the NFT's utility while it serves as collateral.

Proposed use cases

The following use cases are discussed in ERC-7721.

Use case Description
NFT-backed loans Lock NFTs in the owner's wallet instead of transferring them to a lending protocol. Transfer restrictions support the collateral arrangement while preserving utility.
NFT rentals with little or no collateral Borrowers pay a fee to use the NFT but cannot freely transfer it, reducing risk to lenders. A service contract is expected to return it to the lender when the rental period ends, according to the service's rules.
BNPL (Buy Now Pay Later) Buyers receive a locked NFT and can use it immediately, but cannot sell it until payment is completed. The service may return it to the seller if the buyer defaults, with fees handled according to the arrangement.
Composability Combine financial tools, for example by borrowing against an NFT while renting it out to generate income, subject to compatible permissions and protocol rules.
Primary sales Mint an NFT after partial payment and settle the outstanding balance later.
Soulbound tokens Operate NFTs in a non-transferable or restricted-transfer manner. An organization can mint a token, deliver it to a user, and lock it under its own locker authority.
Improved security Owners can keep NFTs in hot wallets, such as MetaMask, while assigning unlocking authority to a cold wallet. Even if the hot wallet is compromised, ordinary transfers of locked tokens remain restricted without the cold wallet's authority.

Soulbound generally refers to NFTs that cannot be transferred or whose transfers are severely restricted. Here, the intention is to let an organization retain locker authority so the user cannot freely transfer the NFT.

Differences from other locking proposals

ERC-7721 distinguishes itself from other NFT locking proposals in the following ways.

Focus on minimal locking and unlocking

ERC-7721 does not include specific conditions such as time-based unlocking in the standard. Unlocking conditions such as repayment, expiry, or another agreed condition can be implemented by the protocol's smart contract.

The design provides locking and unlocking primitives while leaving different unlocking conditions to higher-level protocols.

Separating locker and approver permissions

ERC-7721 distinguishes unlocking authority (locker) from operational permissions granted through approvals (approver).

  • Using an approval to lock tokens, and allowing the approved party to unlock or withdraw them, is suitable for third-party-operated arrangements such as rentals, lending, and BNPL.
  • A design that allows locking without granting revocation rights, while still allowing an authorized locker to unlock when appropriate, is suitable for account-bound or similar NFTs.

Revocation means withdrawing an existing right, such as invalidating a permission previously granted to another party.

Introducing transferAndLock

ERC-7721 proposes the transferAndLock function. It performs a transfer and lock together and can optionally configure approval at the same time.

This makes it possible to lock an NFT as soon as it is received while optionally retaining a mechanism for subsequent revocation or recovery.

Specification

Overview

ERC-7721 provides a standard method for locking and unlocking ERC-1155 tokens while they remain in the current owner's wallet.

Locking does not move tokens out of the owner's wallet. A contract implementing ERC-7721 restricts the quantity of tokens available for transfer.

Locks apply to both a tokenId and an amount. Because ERC-1155 supports multiple units of the same tokenId, the mechanism tracks the quantity that is locked.

Basic locking and unlocking behavior

Locking

There are two ways to lock tokens.

The first lets the owner specify a locker when creating the lock. The function lock(tokenId, account, _locker, amount) explicitly designates the address authorized to unlock the tokens.

The second lets an owner or an approved address create a lock with itself as the locker. Calling lock(tokenId, account, amount) sets msg.sender as the locker.

In both cases, the account whose tokens are being locked must have a sufficient available balance. A call reverts if the caller does not satisfy the ownership or approval requirement for the selected overload.

Unlocking

Only the address designated as the locker can unlock tokens locked under its authority. The function unlock(tokenId, account, amount) unlocks the specified quantity.

An attempt to unlock more tokens than are locked by that locker reverts.

Extending approvals (Approval)

In addition to ordinary ERC-1155 approvals, ERC-7721 introduces approvals scoped to a token ID.

setApprovalForId(tokenId, operator, amount) sets the quantity that an operator can use for the specified tokenId.

getApprovalForId(tokenId, account, operator) returns the approved quantity.

This allows fine-grained control over which token ID an operator can use and how many units it can operate. The design supports use cases such as rental and partial use of token balances.

Reading lock status

getLocked(tokenId, account, operator) returns the quantity locked by the specified operator on the given account.

  • If that operator has not locked any units, the function returns 0.
  • Otherwise, it returns the locked quantity.

This return value helps determine the quantity available for transfer. For an account with multiple lockers, the total locked quantity must also be considered.

Transfer restrictions

Contracts implementing ERC-7721 impose additional restrictions on ERC-1155's safeTransferFrom.

Ordinary transfers cannot move locked quantities. The maximum available quantity for an ordinary transfer is calculated as follows.

text
移転可能数量 = 残高 - getLocked(...)

An attempt to transfer more than the available unlocked quantity reverts, subject to the authorized-locker behavior described in the security section.

The purpose of transferAndLock

ERC-7721 provides the transferAndLock function.

This function transfers and locks tokens as a single operation. It can also grant approval to the locker if required.

The function is recommended in the following situations.

  • When tokens must be locked immediately after transfer.
  • When unlocking or revocation may be needed following the transfer.

Interface

IERCLockable1155.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity >=0.7.0 <0.9.0;

/// @title Lockable Extension for ERC1155
/// @dev Interface for the Lockable extension
/// @author piyush-chittara 

interface IERCLockable1155 is IERC1155{

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

    /**
     * @dev Emitted when tokenId is unlocked
     */
    event Unlock (uint256 indexed tokenId, address account, address _locker, uint256 amount);

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

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

    /**
     * @dev Unlocks the tokenId if msg.sender is locker
     */
    function unlock(uint256 tokenId, address account, uint256 amount) 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(address from, address to, uint256 tokenId, uint256 amount, bool setApprove) external;

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

    function setApprovalForId(uint256 tokenId, address operator, uint256 amount) external;
}

Events

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

Emitted when a quantity of a tokenId is locked. It notifies external observers that tokens have been locked and identifies the token ID, holding account, locker, and locked amount.

Parameters

  • tokenId
    • ID of the token being locked.
  • account
    • Account holding the tokens.
  • _locker
    • Address authorized to unlock them.
  • amount
    • Quantity locked.
Unlock
javascript
event Unlock(uint256 indexed tokenId, address account, address _locker, uint256 amount);

Emitted when a quantity of a tokenId is unlocked. The event records which locker unlocked which token ID and how many units were unlocked.

Parameters

  • tokenId
    • ID of the relevant token.
  • account
    • Account holding the tokens.
  • _locker
    • Address that performed the unlocking.
  • amount
    • Quantity unlocked.

Functions

lock
javascript
function lock(uint256 tokenId, address account, uint256 amount) external;

Locks tokens and designates the caller as the locker. The owner or an approved address can call the function. The locker is set to msg.sender, and the specified quantity becomes unavailable for ordinary transfers.

Parameters

  • tokenId
    • ID of the token being locked.
  • account
    • Account holding the tokens.
  • amount
    • Quantity to lock.
lock
javascript
function lock(uint256 tokenId, address account, address _locker, uint256 amount) external;

Locks tokens and designates an arbitrary locker. Only the owner can call this overload. It is used when unlocking authority needs to be delegated to another party.

Parameters

  • tokenId
    • ID of the token being locked.
  • account
    • Account holding the tokens.
  • _locker
    • Address authorized to unlock them.
  • amount
    • Quantity to lock.
unlock
javascript
function unlock(uint256 tokenId, address account, uint256 amount) external;

Unlocks previously locked tokens. Only the designated locker can perform this operation on its own locked quantity. Attempting to unlock more units than are locked reverts.

Parameters

  • tokenId
    • ID of the relevant token.
  • account
    • Account holding the tokens.
  • amount
    • Quantity to unlock.
transferAndLock
javascript
function transferAndLock(
    address from,
    address to,
    uint256 tokenId,
    uint256 amount,
    bool setApprove
) external;

Transfers tokens and immediately locks them in a single transaction. If setApprove is true, approval is also granted to the locker. The function is recommended for use cases that require a mechanism for revocation after a transfer.

Parameters

  • from
    • Sender address.
  • to
    • Recipient address.
  • tokenId
    • ID of the relevant token.
  • amount
    • Quantity to transfer and lock.
  • setApprove
    • Whether to grant approval at the same time.
getLocked
javascript
function getLocked(
    uint256 tokenId,
    address account,
    address operator
) external view returns (uint256);

Returns the quantity locked under the specified conditions. It returns the amount locked by operator on account, or 0 if no units are locked by that operator.

Parameters

  • tokenId
    • ID of the relevant token.
  • account
    • Address holding the tokens.
  • operator
    • Locker or other address being queried.

Return value

  • uint256
    • Locked quantity.
setApprovalForId
javascript
function setApprovalForId(
    uint256 tokenId,
    address operator,
    uint256 amount
) external;

Sets an approved quantity for a particular tokenId. It specifies the amount that an operator may use for that token ID, allowing finer-grained control than ERC-1155's approval for all tokens.

Parameters

  • tokenId
    • ID of the relevant token.
  • operator
    • Address receiving approval.
  • amount
    • Quantity to approve.

Additional considerations

ERC-7721 exposes transferAndLock(address from, address to, uint256 tokenId, uint256 amount, bool setApprove). This function transfers tokens and locks them on the recipient's side in a single operation. The recipient holds the tokens but cannot freely transfer the locked quantity. It provides a mechanism for conditional ownership.

The optional setApprove flag grants approval to the locker when set to true. This gives the locker not only unlocking authority but also permission to move tokens within the scope of the approval.

ERC-7721 does not determine the actual conditions under which revocation is permitted. Those conditions can be defined by surrounding contracts. A service contract might, for instance, recover an NFT when installment payments stop, return it when a rental period expires, or release it when repayment is complete. The approved locker, often the service contract itself, can perform the relevant recovery or return.

In summary, transferAndLock supports the following outcomes.

Desired outcome Role of transferAndLock
Deliver the tokenId to the recipient for immediate use transfer
Prevent free resale or transfer to third parties lock
Allow recovery or unlocking under specified conditions Grant approval with setApprove=true, with the conditions defined by surrounding contracts.

The recipient can use the NFT without being free to resell it. This behavior is particularly suitable for BNPL and rental applications.

Compatibility

ERC-7721 is compatible with ERC-1155 in the sense that it adds locking functionality without replacing the basic ERC-1155 interface or its ordinary behavior for unlocked tokens.

Existing upgradeable ERC-1155 contracts can incorporate ERC-7721 locking functionality through an implementation upgrade, provided the upgrade preserves their existing state and interfaces. Liquidity mechanisms such as lending, rentals, and installment payments that previously required external custody can then be supported by functionality on the token contract itself.

Reference implementation

https://eips.ethereum.org/assets/eip-7721/IERC7721.sol

https://eips.ethereum.org/assets/eip-7721/ERC7721.sol

Security

Locked quantities cannot be freely transferred

Once an amount is locked, it cannot be freely transferred from the account holding it. This restriction is central to ERC-7721. An ordinary transfer through safeTransferFrom, for example, reverts when it attempts to exceed the available unlocked balance. This supports arrangements such as rentals and collateral where users must not be able to dispose of the encumbered assets unilaterally.

An approved locker can transfer locked tokens

The proposal allows a caller that is both the locker and approved to transfer tokens to exercise that authority even when the relevant tokens are locked.

In other words, granting approval (approval) in addition to unlocking authority lets the locker perform a transfer. The setApprove=true option in transferAndLock establishes this combination of permissions. This allows the locker, such as a service contract, to perform recovery or return operations associated with revocation.

Although useful, a poor design may grant the locker more power than intended. Operators should explicitly define when approval is granted and what the approved locker may do.

An inaccessible locker may cause a permanent lock

The proposal uses the expression "in-accesible account" to describe an account that cannot be accessed. Assigning locker authority to an EOA whose private key has been lost or to a contract that does not operate as expected can make unlocking impossible, potentially leaving tokens permanently locked.

The expression "un-verified contract address" refers to a contract whose implementation has not been verified or is unknown. Choosing a contract whose implementation is not public, or which does not provide the expected unlocking functionality, may prevent the tokens from ever being unlocked.

Locking serves as a security measure, but an incorrect configuration can be irreversible. In particular, when an owner can freely designate a locker using lock(tokenId, account, _locker, amount), a configuration mistake can directly result in inaccessible assets.

No specific MEV considerations

Maximal extractable value (MEV) refers to value extracted through mechanisms such as transaction ordering. The proposal states that there are no specific MEV considerations for lockable tokens themselves because locking and unlocking are limited to authorized parties.

The rationale is that unauthorized third parties cannot freely invoke locking or unlocking operations to profit from changing their order. This does not imply that applications built on the mechanism, including financial protocols, are immune to MEV or transaction-ordering risks.

Citation

Piyush Chittara (@piyush-chittara), "ERC-7721: Lockable Extension for ERC-1155 [DRAFT]," Ethereum Improvement Proposals, no. 7721, May 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7721.

Conclusion

ERC-7721 proposes a locking mechanism that restricts transfers of ERC-1155 NFTs by token ID and quantity while allowing the owner to keep the tokens in their wallet.