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 ERC7695, which proposes a mechanism for delegating NFT usage rights to another user without changing its owner.
The following explanation translates, summarizes, and supplements the material linked below.
I also cover various EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.
Overview
ERC7695 extends ERC721 to specify who may use an NFT in different contexts and to provide a locking mechanism. Locking here means not merely depositing an NFT somewhere to prevent movement, but also preventing unauthorized transfers while allowing usage rights to be granted temporarily.
For more on ERC721, see the following article.
In traditional ERC721, the central role is essentially the Owner. The Owner can transfer the NFT, and ownership itself establishes eligibility for benefits in many dApps. In financial use cases such as staking, collateral, and rentals, however, NFTs are often transferred to a contract to lock them. This conflicts with benefits reserved for owners in other dApps.
ERC7695 addresses this problem through two concepts: Ownership Delegation and Contexts.
- Ownership Delegation A mechanism for temporarily granting someone else the right to use the NFT without changing the original Owner. It standardizes the idea that the owner remains the same while the user changes.
- Contexts A framework for distinguishing the purpose or situation in which usage rights apply. The same NFT may be used as equipment in a game, for voting, or as a rental, for example. ERC7695 makes it possible to define who may use the NFT in each context.
ERC7695 then defines the following roles.
| Role | Meaning | Typical capabilities |
|---|---|---|
| Owner | Ultimate rights holder of the NFT | Retains underlying ownership and benefits, such as holder perks |
| Controller | Role managing a context | Determines who can use the NFT for a particular purpose and controls operations |
| User | Role actually using the NFT | Can use the NFT within the scope defined by the context |
The Controller is responsible for operations within that context. In a rental context, for example, the entity managing the rental agreement (such as a contract or operator) becomes the Controller and assigns the renter as the User. Contexts are separate containers for rights associated with different purposes. Different contexts can specify different authorized users for the same NFT.
ERC7695 aims to expand the utility of NFTs across multiple dApps while protecting the Owner's benefits and rights. Because the Owner remains the same, it is easier to retain rights reserved for owners, such as holder perks, while temporarily granting someone else usage rights.
Motivation
ERC721 NFTs have the following uses in financial applications.
| Use case | Objective | Common traditional approach |
|---|---|---|
| Staking | Deposit an NFT to earn rewards | Transfer the NFT to a staking contract and lock it |
| Collateral (mortgage) | Use an NFT as collateral to obtain income or funds | Transfer the NFT to a collateral contract and encumber it |
| Rental and delegation | Receive compensation for allowing someone else to use an NFT, such as by leasing usage rights | Transfer ownership temporarily, or have a contract hold the NFT and manage its use |
The problem is that locking often requires transferring ownership. Under conventional designs, depositing and transferring an NFT to a contract makes that contract the on-chain Owner. Consequently, if another dApp requires being the Owner to receive benefits, the original holder may no longer qualify.
Consider the following scenario.
- Holding an NFT entitles the holder to receive an airdrop (free token distribution) from another project.
- Depositing the NFT in a staking or collateral contract changes the Owner to that contract.
- The airdrop is then sent to the contract, or the NFT no longer qualifies at all.
- The original holder wants to make use of the NFT but loses the holder benefits.
To avoid this problem, dApps providing benefits would need to recognize as many staking and collateral contracts as possible and distribute benefits to the original holders even through those contracts. In practice, this is often difficult. There are countless contracts, leaving dApps to decide which are legitimate, which specifications to support, and how to keep up with updates.
This stems from the fact that only the Owner role is standardized. Protocols built on ERC721 define non-ownership roles, such as users and managers, individually. One dApp may therefore treat a deposit contract as the Owner while another implements custom logic to accommodate the original holder, making interoperability fragile.
ERC7695 addresses this difficulty at the standards level by organizing use cases into contexts, assigning management to Controllers, and assigning usage to Users. It separates ownership (Owner) from other roles and explicitly addresses the temporary grant of usage rights through Ownership Delegation.
This offers dApp developers the following benefits.
- They no longer need to force who owns the NFT and who can use it into the same concept. The Owner remains the reference point for benefits and rights, while use can be entrusted to the User.
- A common model (Controller / User / Contexts) across protocols makes it easier to build infrastructure and supporting tools, including indexers, wallet displays, and permission checks.
- Using an NFT does not necessarily compromise the Owner's position, reducing conflicts between holder benefits and financial use cases.
Conceptual relationship diagram
flowchart LR
O[Owner<br/>所有者] -->|Ownership Delegation<br/>所有権は維持したまま権利を委任| C[Controller<br/>コンテキスト内の管理者]
C -->|ContextごとにUserを指定| U[User<br/>実利用者]
subgraph X[Contexts(用途の箱)]
X1[例: レンタル]
X2[例: ステーキング利用]
X3[例: ゲーム内利用]
end
C --> X
U --> X
The diagram illustrates how the Owner remains unchanged while a Controller can designate a User for each context or purpose. This is the foundation for expanding NFT utility while protecting the Owner's rights.
Specification
Definitions
Token context
A token context specifies the purpose for which an NFT is used. It refers to the relationship connecting an NFT (token) to a context.
Each token context is assigned exactly one user authorized to use the NFT for that purpose. This means that different users can simultaneously use the same NFT for different purposes.
Each context has the following two roles.
- Controller The party responsible for managing the context. It has authority over operations such as assigning authorized users and locking the token.
- User The party permitted to use the NFT within that context.
The important distinction is between the owner of the NFT as a whole and the person using it within a context.
Ownership rights
Rather than focusing solely on the Owner role, ERC7695 explicitly defines the specific rights associated with ownership. Token ownership grants the ability to perform the following operations.
- Transfer the token to a new owner.
- Attach the token to one or more contexts.
- Detach the token from one or more contexts.
Together, these are referred to as Ownership Rights. The distinguishing feature is that the specification defines what a party can do, not merely the state of being the Owner.
Ownership delegation
Ownership delegation is a mechanism for separating the Owner from Ownership Rights.
The Owner remains the ultimate owner of the token but can delegate ownership rights to another account for a specified period. This delegation has an expiration time.
During the delegation period, the Owner cannot exercise ownership rights directly. When the delegation expires, those rights automatically return to the Owner.
This allows the Owner to temporarily grant another party the authority needed for management and operation without changing ownership.
Roles
ERC7695 clearly distinguishes the roles associated with a token. The following tables summarize their responsibilities, permissions, and cardinality per token.
Token-wide roles
| Role | Responsibilities and permissions | Number per token |
|---|---|---|
| Owner | Holds ownership rights by default. Can delegate those rights to another account for a specified period. | 1 |
| Ownership Delegatee | Holds ownership rights during the delegation period. Can relinquish them before expiration. | At most 1 |
| Ownership Manager | The party currently holding ownership rights: the Owner when there is no delegation, or the Ownership Delegatee during delegation. | 1 |
Ownership Manager identifies the party currently able to exercise ownership rights. This abstract role eliminates the need to determine each time whether that party is the Owner or the Delegatee.
Context-specific roles
| Role | Responsibilities and permissions | Number |
|---|---|---|
| Controller | Manages the context. Can transfer the Controller role, assign the User, and lock or unlock token transfers. | 1 per context |
| User | Party authorized to use the NFT within the context. | 1 per context |
The Controller is the party responsible for that use case. The User is the party actually using the NFT, without management authority.
Relationship between roles and permissions
The following diagram illustrates the overall relationship.
flowchart LR O[Owner<br/>最終的な所有者] -->|所有権の委任| D[Ownership Delegatee] O --> M[Ownership Manager] D --> M M -->|コンテキストを追加・削除| Ctx[Token Context] Ctx --> C[Controller] C -->|Userを設定| U[User] C -->|移転ロック制御| T[NFT Transfer]
This structure makes the division of responsibilities clear.
- The Owner remains unchanged.
- The Ownership Manager exercises ownership rights.
- The Controller manages each context.
- The User actually uses the NFT.
Interface
/// Note: the ERC-165 identifier for this interface is 0x486b6fba.
interface IERC7695 /* is IERC721, IERC165 */ {
/// @dev This emits when a context is updated by any mechanism.
event ContextUpdated(bytes32 indexed ctxHash, address indexed controller, uint64 detachingDuration);
/// @dev This emits when a token is attached to a certain context by any mechanism.
event ContextAttached(bytes32 indexed ctxHash, uint256 indexed tokenId);
/// @dev This emits when a token is requested to detach from a certain context by any mechanism.
event ContextDetachmentRequested(bytes32 indexed ctxHash, uint256 indexed tokenId);
/// @dev This emits when a token is detached from a certain context by any mechanism.
event ContextDetached(bytes32 indexed ctxHash, uint256 indexed tokenId);
/// @dev This emits when a user is assigned to a certain context by any mechanism.
event ContextUserAssigned(bytes32 indexed ctxHash, uint256 indexed tokenId, address indexed user);
/// @dev This emits when a token is (un)locked in a certain context by any mechanism.
event ContextLockUpdated(bytes32 indexed ctxHash, uint256 indexed tokenId, bool locked);
/// @dev This emits when the ownership delegation is started by any mechanism.
event OwnershipDelegationStarted(uint256 indexed tokenId, address indexed delegatee, uint64 until);
/// @dev This emits when the ownership delegation is accepted by any mechanism.
event OwnershipDelegationAccepted(uint256 indexed tokenId, address indexed delegatee, uint64 until);
/// @dev This emits when the ownership delegation is stopped by any mechanism.
event OwnershipDelegationStopped(uint256 indexed tokenId, address indexed delegatee);
/// @notice Gets the longest duration the detaching can happen.
function maxDetachingDuration() external view returns (uint64);
/// @notice Gets controller address and detachment duration of a context.
/// @dev MUST revert if the context is not existent.
/// @param ctxHash A hash of context to query the controller.
/// @return controller The address of the context controller.
/// @return detachingDuration The duration must be waited for detachment in second(s).
function getContext(bytes32 ctxHash) external view returns (address controller, uint64 detachingDuration);
/// @notice Creates a new context.
/// @dev MUST revert if the context is already existent.
/// MUST revert if the controller address is zero address.
/// MUST revert if the detaching duration is larger than max detaching duration.
/// MUST emit the event {ContextUpdated} to reflect context created and controller set.
/// @param controller The address that controls the created context.
/// @param detachingDuration The duration must be waited for detachment in second(s).
/// @param ctxMsg The message of new context to be used for hashing.
/// @return ctxHash Hash of the created context.
function createContext(address controller, uint64 detachingDuration, bytes calldata ctxMsg)
external
returns (bytes32 ctxHash);
/// @notice Updates an existing context.
/// @dev MUST revert if method caller is not the current controller.
/// MUST revert if the context is non-existent.
/// MUST revert if the new controller address is zero address.
/// MUST revert if the detaching duration is larger than max detaching duration.
/// MUST emit the event {ContextUpdated} on success.
/// @param ctxHash Hash of the context to set.
/// @param newController The address of new controller.
/// @param newDetachingDuration The new duration must be waited for detachment in second(s).
function updateContext(bytes32 ctxHash, address newController, uint64 newDetachingDuration) external;
/// @notice Queries if a token is attached to a certain context.
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to query.
/// @return True if the token is attached to the context, false if not.
function isAttachedWithContext(bytes32 ctxHash, uint256 tokenId) external view returns (bool);
/// @notice Attaches a token with a certain context.
/// @dev See "attachContext rules" in "Token (Un)lock Rules".
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be attached.
/// @param data Additional data with no specified format, MUST be sent unaltered in call to the {IERC7695ContextCallback} hook(s) on controller.
function attachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
/// @notice Requests to detach a token from a certain context.
/// @dev See "requestDetachContext rules" in "Token (Un)lock Rules".
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be detached.
/// @param data Additional data with no specified format, MUST be sent unaltered in call to the {IERC7695ContextCallback} hook(s) on controller.
function requestDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
/// @notice Executes context detachment.
/// @dev See "execDetachContext rules" in "Token (Un)lock Rules".
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be detached.
/// @param data Additional data with no specified format, MUST be sent unaltered in call to the {IERC7695ContextCallback} hook(s) on controller.
function execDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
/// @notice Finds the context user of a token.
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be detached.
/// @return user Address of the context user.
function getContextUser(bytes32 ctxHash, uint256 tokenId) external view returns (address user);
/// @notice Updates the context user of a token.
/// @dev MUST revert if the method caller is not context controller.
/// MUST revert if the context is non-existent.
/// MUST revert if the token is not attached to the context.
/// MUST emit the event {ContextUserAssigned} on success.
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be update.
/// @param user Address of the new user.
function setContextUser(bytes32 ctxHash, uint256 tokenId, address user) external;
/// @notice Queries if the lock a token is locked in a certain context.
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be queried.
/// @return True if the token context is locked, false if not.
function isTokenContextLocked(bytes32 ctxHash, uint256 tokenId) external view returns (bool);
/// @notice (Un)locks a token in a certain context.
/// @dev See "setContextLock rules" in "Token (Un)lock Rules".
/// @param ctxHash Hash of a context.
/// @param tokenId The NFT to be queried.
/// @param lock New status to be (un)locked.
function setContextLock(bytes32 ctxHash, uint256 tokenId, bool lock) external;
/// @notice Finds the ownership manager of a specified token.
/// @param tokenId The NFT to be queried.
/// @return manager Address of delegatee.
function getOwnershipManager(uint256 tokenId) external view returns(address manager);
/// @notice Finds the ownership delegatee of a token.
/// @dev MUST revert if there is no (or an expired) ownership delegation.
/// @param tokenId The NFT to be queried.
/// @return delegatee Address of delegatee.
/// @return until The delegation expiry time.
function getOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);
/// @notice Finds the pending ownership delegatee of a token.
/// @dev MUST revert if there is no (or an expired) pending ownership delegation.
/// @param tokenId The NFT to be queried.
/// @return delegatee Address of pending delegatee.
/// @return until The delegation expiry time in the future.
function pendingOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);
/// @notice Starts ownership delegation and retains ownership until a specific timestamp.
/// @dev Replaces the pending delegation if any.
/// See "startDelegateOwnership rules" in "Ownership Delegation Rules".
/// @param tokenId The NFT to be delegated.
/// @param delegatee Address of new delegatee.
/// @param until The delegation expiry time.
function startDelegateOwnership(uint256 tokenId, address delegatee, uint64 until) external;
/// @notice Accepts ownership delegation request.
/// @dev See "acceptOwnershipDelegation rules" in "Ownership Delegation Rules".
/// @param tokenId The NFT to be accepted.
function acceptOwnershipDelegation(uint256 tokenId) external;
/// @notice Stops the current ownership delegation.
/// @dev See "stopOwnershipDelegation rules" in "Ownership Delegation Rules".
/// @param tokenId The NFT to be stopped.
function stopOwnershipDelegation(uint256 tokenId) external;
}The following sections describe the events and functions of ERC7695. The Ownership Delegation Rules / Token (Un)lock Rules / Additional Transfer Rules are reflected in the details of the relevant functions.
// Note: ERC-165 identifier for IERC7695 is 0x486b6fba.
interface IERC7695 /* is IERC721, IERC165 */ {
event ContextUpdated(bytes32 indexed ctxHash, address indexed controller, uint64 detachingDuration);
event ContextAttached(bytes32 indexed ctxHash, uint256 indexed tokenId);
event ContextDetachmentRequested(bytes32 indexed ctxHash, uint256 indexed tokenId);
event ContextDetached(bytes32 indexed ctxHash, uint256 indexed tokenId);
event ContextUserAssigned(bytes32 indexed ctxHash, uint256 indexed tokenId, address indexed user);
event ContextLockUpdated(bytes32 indexed ctxHash, uint256 indexed tokenId, bool locked);
event OwnershipDelegationStarted(uint256 indexed tokenId, address indexed delegatee, uint64 until);
event OwnershipDelegationAccepted(uint256 indexed tokenId, address indexed delegatee, uint64 until);
event OwnershipDelegationStopped(uint256 indexed tokenId, address indexed delegatee);
function maxDetachingDuration() external view returns (uint64);
function getContext(bytes32 ctxHash) external view returns (address controller, uint64 detachingDuration);
function createContext(address controller, uint64 detachingDuration, bytes calldata ctxMsg) external returns (bytes32 ctxHash);
function updateContext(bytes32 ctxHash, address newController, uint64 newDetachingDuration) external;
function isAttachedWithContext(bytes32 ctxHash, uint256 tokenId) external view returns (bool);
function attachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
function requestDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
function execDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;
function getContextUser(bytes32 ctxHash, uint256 tokenId) external view returns (address user);
function setContextUser(bytes32 ctxHash, uint256 tokenId, address user) external;
function isTokenContextLocked(bytes32 ctxHash, uint256 tokenId) external view returns (bool);
function setContextLock(bytes32 ctxHash, uint256 tokenId, bool lock) external;
function getOwnershipManager(uint256 tokenId) external view returns(address manager);
function getOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);
function pendingOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);
function startDelegateOwnership(uint256 tokenId, address delegatee, uint64 until) external;
function acceptOwnershipDelegation(uint256 tokenId) external;
function stopOwnershipDelegation(uint256 tokenId) external;
}
// Note: ERC-165 identifier for IERC7695Enumerable is 0xcebf44b7.
interface IERC7695Enumerable /* is IERC165 */ {
function getContext(uint256 index) external view returns(bytes32 ctxHash);
function getContextCount() external view returns(uint256);
function getAttachedContext(uint256 tokenId, uint256 index) external view returns(bytes32 ctxHash);
function getAttachedContextCount(uint256 tokenId) external view returns(uint256);
}
// Note: ERC-165 identifier for IERC7695ContextCallback is 0xad0491f1.
interface IERC7695ContextCallback /* is IERC165 */ {
function onAttached(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;
function onDetachRequested(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;
function onExecDetachContext(bytes32 ctxHash, uint256 tokenId, address user, address operator, bytes calldata data) external;
}Events
ContextUpdated
event ContextUpdated(bytes32 indexed ctxHash, address indexed controller, uint64 detachingDuration);Event emitted when a context is created or updated.
It signals that a context has been created or updated and allows the current values of controller and detachingDuration to be tracked.
Parameters
ctxHash- Hash identifying the target context.
controller- Address of the Controller managing the context.
detachingDuration- Number of seconds to wait before executing detachment.
ContextAttached
event ContextAttached(bytes32 indexed ctxHash, uint256 indexed tokenId);Event emitted when a token is attached to a context. It indicates that the NFT has been associated with the specified context. From then on, the token is subject to user assignment and lock control within that context.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
ContextDetachmentRequested
event ContextDetachmentRequested(bytes32 indexed ctxHash, uint256 indexed tokenId);Event emitted when detachment is requested for a locked token.
It indicates that the token context is locked, preventing immediate detachment and placing it into a waiting state.
After detachingDuration has elapsed, the actual detachment can be performed with execDetachContext.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
ContextDetached
event ContextDetached(bytes32 indexed ctxHash, uint256 indexed tokenId);Event emitted when a token is detached from a context.
It indicates that the association with the context has been removed.
Depending on the lock state, it is emitted immediately or when execDetachContext is executed.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
ContextUserAssigned
event ContextUserAssigned(bytes32 indexed ctxHash, uint256 indexed tokenId, address indexed user);Event emitted when a context user is assigned or updated. It indicates that the user in the specified context has changed. Indexers and other systems can track changes to the user.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
user- Address of the new user.
ContextLockUpdated
event ContextLockUpdated(bytes32 indexed ctxHash, uint256 indexed tokenId, bool locked);Event emitted when a token within a context is locked or unlocked. It indicates that the Controller has changed the lock state. If detachment has already been requested, the lock operation itself is not permitted.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
locked- Updated lock state.
OwnershipDelegationStarted
event OwnershipDelegationStarted(uint256 indexed tokenId, address indexed delegatee, uint64 until);Event emitted when ownership delegation is initiated.
It indicates that the Owner has initiated delegation and set delegatee and until.
It can also be treated as a signal that a pending delegation has begun.
Parameters
tokenId- Token ID of the target NFT.
delegatee- Delegatee address.
until- Delegation expiration timestamp.
OwnershipDelegationAccepted
event OwnershipDelegationAccepted(uint256 indexed tokenId, address indexed delegatee, uint64 until);Event emitted when ownership delegation is accepted.
It indicates that the delegatee has accepted the delegation and will be treated as the Ownership Manager during the delegation period.
Parameters
tokenId- Token ID of the target NFT.
delegatee- Address that accepted the delegation.
until- Delegation expiration timestamp.
OwnershipDelegationStopped
event OwnershipDelegationStopped(uint256 indexed tokenId, address indexed delegatee);Event emitted when ownership delegation is stopped. It indicates that an accepted delegation has been stopped and that the Owner is once again the Ownership Manager.
Parameters
tokenId- Token ID of the target NFT.
delegatee- Delegatee address whose delegation was stopped.
Functions
maxDetachingDuration
function maxDetachingDuration() external view returns (uint64);Returns the maximum detachment waiting period.
It returns the upper bound for detachingDuration that can be specified in createContext and updateContext.
Return value
uint64- Maximum waiting period (seconds).
getContext
function getContext(bytes32 ctxHash) external view returns (address controller, uint64 detachingDuration);Retrieves a context's Controller and detachment waiting period.
If the context does not exist, the function will revert.
detachingDuration is the number of seconds that must elapse before a locked token can be detached.
Parameters
ctxHash- Hash identifying the context.
Return values
controller- Controller address.
detachingDuration- Detachment waiting period (seconds).
createContext
function createContext(address controller, uint64 detachingDuration, bytes calldata ctxMsg)
external
returns (bytes32 ctxHash);Creates a new context.
If the context already exists, the function will revert.
If controller is the zero address, the function will revert.
If detachingDuration exceeds maxDetachingDuration, the function will revert.
On success, it will emit the ContextUpdated event.
ctxMsg is the input data used to create the context, and the return value ctxHash is its hash.
Parameters
controller- Controller of the context being created.
detachingDuration- Detachment waiting period (seconds).
ctxMsg- Message used to hash the context.
Return value
ctxHash- Hash of the newly created context.
updateContext
function updateContext(bytes32 ctxHash, address newController, uint64 newDetachingDuration) external;Updates the Controller and waiting period of an existing context.
If the caller is not the current Controller, the function will revert.
If the context does not exist, the function will revert.
If newController is the zero address, the function will revert.
If newDetachingDuration exceeds maxDetachingDuration, the function will revert.
On success, it will emit the ContextUpdated event.
Parameters
ctxHash- Hash of the context being updated.
newController- Address of the new Controller.
newDetachingDuration- New detachment waiting period (seconds).
isAttachedWithContext
function isAttachedWithContext(bytes32 ctxHash, uint256 tokenId) external view returns (bool);Returns whether a token is attached to a context.
Returns true if the specified tokenId is associated with the context identified by ctxHash.
Parameters
ctxHash- Context hash.
tokenId- Token ID of the target NFT.
Return value
bool- True if attached.
attachContext
function attachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;Attaches a token to a context.
The function will revert unless the caller is the Ownership Manager, an approved operator of the Ownership Manager, or, only when no delegation is active, the NFT's approved address.
If the context does not exist, the function will revert.
If the token is already attached to that context, the function will revert.
On success, it will emit the ContextAttached event.
After the conditions are met, it must call onAttached if controller is a contract.
If the call to onAttached fails, the function reverts.
Pass data unchanged to the data parameter of onAttached.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
data- Arbitrary data passed unchanged to the callback.
requestDetachContext
function requestDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;Requests detachment of a token.
If detachment has already been requested for the same context, the function will revert.
The function will revert unless the caller is the context Controller, the Ownership Manager, an approved operator of the Ownership Manager, or, only when no delegation is active, the NFT's approved address.
Subsequent behavior depends on the lock state.
| State | Event | Callback | execDetachContext |
|---|---|---|---|
| The caller is the Controller, or the token is not locked | emit ContextDetached |
Call onExecDetachContext if controller is a contract (ignore the result) |
Must not be called |
| The token is locked | emit ContextDetachmentRequested |
Call onDetachRequested if controller is a contract (ignore the result) |
Required after waiting |
If the token is not locked, detachment is completed within this function. If it is locked, only the request is recorded, and execDetachContext is required after detachingDuration has elapsed.
Pass data unchanged to the applicable callback.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
data- Arbitrary data passed unchanged to the callback.
execDetachContext
function execDetachContext(bytes32 ctxHash, uint256 tokenId, bytes calldata data) external;Executes detachment of a token for which detachment has been requested.
The function will revert unless the caller is the Ownership Manager, an approved operator of the Ownership Manager, or, only when no delegation is active, the NFT's approved address.
If no detachment request exists, the function will revert.
It also uses detachingDuration from getContext(ctxHash) and will revert if the specified number of seconds has not elapsed since the request.
On success, it will emit the ContextDetached event.
After the conditions are met, it must call onExecDetachContext if controller is a contract.
The result of the call is ignored.
Pass data unchanged to onExecDetachContext.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
data- Arbitrary data passed unchanged to the callback.
getContextUser
function getContextUser(bytes32 ctxHash, uint256 tokenId) external view returns (address user);Retrieves the context user of a token.
Returns the user address for tokenId within the specified context.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
Return value
user- User address.
setContextUser
function setContextUser(bytes32 ctxHash, uint256 tokenId, address user) external;Updates the context user.
If the caller is not the context Controller, the function will revert.
If the context does not exist, the function will revert.
If the token is not attached to that context, the function will revert.
On success, it will emit the ContextUserAssigned event.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
user- Address of the new user.
isTokenContextLocked
function isTokenContextLocked(bytes32 ctxHash, uint256 tokenId) external view returns (bool);Returns whether the token is locked within the context.
If it is locked, detachment cannot occur immediately; the sequence is requestDetachContext, a waiting period, then execDetachContext.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
Return value
booltrueif locked.
setContextLock
function setContextLock(bytes32 ctxHash, uint256 tokenId, bool lock) external;Locks or unlocks a token within a context.
If the context does not exist, the function will revert.
If the token is not attached to that context, the function will revert.
If detachment has already been requested, the function will revert.
If the caller is not the context Controller, the function will revert.
On success, it will emit the ContextLockUpdated event.
In this scenario, the lock operation succeeds when no detachment has been requested and always results in a revert if a request exists.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
lock- New lock state.
getOwnershipManager
function getOwnershipManager(uint256 tokenId) external view returns(address manager);Retrieves the current Ownership Manager.
This read interface is intended to return the delegatee if the delegation is active and accepted, and the Owner otherwise.
Parameters
tokenId- Token ID of the target NFT.
Return value
manager- Address of the Ownership Manager.
getOwnershipDelegatee
function getOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);Retrieves the delegatee and expiration of the currently active ownership delegation.
If no active delegation exists or it has expired, the function will revert.
Parameters
tokenId- Token ID of the target NFT.
Return values
delegatee- Delegatee address.
until- Delegation expiration timestamp.
pendingOwnershipDelegatee
function pendingOwnershipDelegatee(uint256 tokenId) external view returns (address delegatee, uint64 until);Retrieves the delegatee and expiration of an unaccepted (pending) ownership delegation.
If no pending delegation exists or it has expired, the function will revert.
Parameters
tokenId- Token ID of the target NFT.
Return values
delegateependingdelegatee address.
until- Delegation expiration timestamp.
startDelegateOwnership
function startDelegateOwnership(uint256 tokenId, address delegatee, uint64 until) external;Initiates ownership delegation.
It can succeed only when no delegation exists.
The function will revert unless the caller is the Owner, an approved operator of the Owner, or the NFT's approved address.
If until is not in the future, the function reverts.
If delegatee is the Owner or the zero address, the function will revert.
If the token does not exist, the function will revert.
On success, it will emit the OwnershipDelegationStarted event.
After the conditions are met, it replaces any existing pending delegation.
Parameters
tokenId- Token ID of the target NFT.
delegatee- Delegatee address.
until- Delegation expiration timestamp.
acceptOwnershipDelegation
function acceptOwnershipDelegation(uint256 tokenId) external;Accepts an ownership delegation.
If no delegation exists, the function will revert.
The function will revert unless the caller is the delegatee or an approved operator of the delegatee.
If until is earlier than the current time, the function will revert.
On success, it emits OwnershipDelegationAccepted.
After the conditions are met, it records the delegatee as the Ownership Manager until expiration.
Parameters
tokenId- Token ID of the target NFT.
stopOwnershipDelegation
function stopOwnershipDelegation(uint256 tokenId) external;Stops an accepted ownership delegation.
If the delegation has not been accepted, the function will revert.
If until is not in the future, the function will revert.
The function will revert unless the caller is the delegatee or an approved operator of the delegatee.
On success, it emits the OwnershipDelegationStopped event.
After the conditions are met, it records the Owner as the Ownership Manager.
Parameters
tokenId- Token ID of the target NFT.
Enumerable extension
/// Note: the ERC-165 identifier for this interface is 0xcebf44b7.
interface IERC7695Enumerable /* is IERC165 */ {
/// @dev Returns a created context in this contract at `index`.
/// An index must be a value between 0 and {getContextCount}, non-inclusive.
/// Note: When using {getContext} and {getContextCount}, make sure you perform all queries on the same block.
function getContext(uint256 index) external view returns(bytes32 ctxHash);
/// @dev Returns the number of contexts created in the contract.
function getContextCount() external view returns(uint256);
/// @dev Returns a context attached to a token at `index`.
/// An index must be a value between 0 and {getAttachedContextCount}, non-inclusive.
/// Note: When using {getAttachedContext} and {getAttachedContextCount}, make sure you perform all queries on the same block.
function getAttachedContext(uint256 tokenId, uint256 index) external view returns(bytes32 ctxHash);
/// @dev Returns the number of contexts attached to the token.
function getAttachedContextCount(uint256 tokenId) external view returns(uint256);
}getContext
function getContext(uint256 index) external view returns(bytes32 ctxHash);Retrieves a context created within the contract by index.
index must be at least 0 and less than getContextCount().
It is intended to be queried together with getContextCount in the same block.
Parameters
index- Index of the context to retrieve.
Return value
ctxHash- Context hash.
getContextCount
function getContextCount() external view returns(uint256);Returns the number of contexts created within the contract.
The Enumerable extension uses this total to enumerate all contexts.
Return value
uint256- Number of contexts.
getAttachedContext
function getAttachedContext(uint256 tokenId, uint256 index) external view returns(bytes32 ctxHash);Retrieves a context attached to a token by index.
index must be at least 0 and less than getAttachedContextCount(tokenId).
It is intended to be queried together with getAttachedContextCount in the same block.
Parameters
tokenId- Token ID of the target NFT.
index- Index of the attached context.
Return value
ctxHash- Context hash.
getAttachedContextCount
function getAttachedContextCount(uint256 tokenId) external view returns(uint256);Returns the number of contexts attached to a token. It returns the total used to enumerate the contexts associated with a particular NFT.
Parameters
tokenId- Token ID of the target NFT.
Return value
uint256- Number of attached contexts.
Controller Interface
/// Note: the ERC-165 identifier for this interface is 0xad0491f1.
interface IERC7695ContextCallback /* is IERC165 */ {
/// @dev This method is called once the token is attached by any mechanism.
/// This function MAY throw to revert and reject the attachment.
/// @param ctxHash The hash of context invoked this call.
/// @param tokenId NFT identifier which is being attached.
/// @param operator The address which called {attachContext} function.
/// @param data Additional data with no specified format.
function onAttached(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;
/// @dev This method is called once the token detachment is requested by any mechanism.
/// @param ctxHash The hash of context invoked this call.
/// @param tokenId NFT identifier which is being requested for detachment.
/// @param operator The address which called {requestDetachContext} function.
/// @param data Additional data with no specified format.
function onDetachRequested(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;
/// @dev This method is called once a token context is detached by any mechanism.
/// @param ctxHash The hash of context invoked this call.
/// @param tokenId NFT identifier which is being detached.
/// @param user The address of the context user which is being detached.
/// @param operator The address which called {execDetachContext} function.
/// @param data Additional data with no specified format.
function onExecDetachContext(bytes32 ctxHash, uint256 tokenId, address user, address operator, bytes calldata data) external;
}onAttached
function onAttached(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;Called after a token has been attached.
It is called when attachContext executes if controller is a contract.
This callback can revert; if it does, the attachment itself fails.
The caller's data is passed unchanged as data.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
operator- Address that called
attachContext.
- Address that called
data- Arbitrary data.
onDetachRequested
function onDetachRequested(bytes32 ctxHash, uint256 tokenId, address operator, bytes calldata data) external;Called when detachment of a locked token is requested.
If requestDetachContext successfully requests detachment of a locked token and controller is a contract, this callback is called.
The result of the call is ignored, and processing continues regardless of success or failure.
The caller's data is passed unchanged as data.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
operator- Address that called
requestDetachContext.
- Address that called
data- Arbitrary data.
onExecDetachContext
function onExecDetachContext(bytes32 ctxHash, uint256 tokenId, address user, address operator, bytes calldata data) external;Called when a token is detached.
If controller is a contract, this callback is called upon detachment through execDetachContext or immediate detachment through requestDetachContext.
The result of the call is ignored, and processing continues regardless of success or failure.
The caller's data is passed unchanged as data.
Parameters
ctxHash- Hash of the target context.
tokenId- Token ID of the target NFT.
user- Context user being detached.
operator- Address that called
execDetachContext.
- Address that called
data- Arbitrary data.
Rationale
Multiple contexts for multiple use cases
ERC7695 reconsiders the design that treats an NFT as an asset usable for only one purpose. At its core is the concept of a token context.
A token context distinguishes who can use an NFT and for what purpose. This makes it possible to handle rental, delegation, staking, and other use cases for the same NFT simultaneously and independently.
Each context has a Controller. The Controller acts as the managing entity for dApps such as rental and delegation applications. Importantly, granting and managing usage rights does not change the NFT's Owner.
Providing locking at the context level also allows trustless dApps to be built. This locking functionality is particularly important for use cases such as staking, which require that the NFT cannot be transferred for a specified period.
Owner-initiated unlocking
ERC7695 is designed so that the Owner can initiate the unlocking process even when the NFT is locked. Conventional designs that make unlocking heavily dependent on the Controller can encounter the following problems.
- The Controller's private key is lost.
- The Controller's contract has a bug or becomes unavailable.
- The operator deliberately stops taking action.
In these situations, the NFT's Owner cannot take action and the asset is effectively frozen.
ERC7695 provides a mechanism for the Owner (or Ownership Manager) to request detachment and complete it after the specified waiting period. This ensures that the NFT can be recovered even if the Controller is absent or unresponsive, improving the security of the asset.
Callback design for attachment and detachment
In ERC7695, the Controller receives callbacks when a context is attached or detached. However, not all callbacks are treated in the same way.
For the detachment-related callbacks onDetachRequested and onExecDetachContext, the call results are deliberately ignored.
This prevents the Controller from becoming a party that can block detachment.
Regardless of the Controller's implementation, it cannot prevent the Owner-side party from completing detachment. The detachment process can therefore be completed by that party without depending on the Controller.
The onAttached callback during attachment is an exception.
If this callback fails, the entire operation will revert.
This allows the Controller to explicitly indicate that the NFT cannot be accepted into the context. The result is an asymmetric design: detachment cannot be blocked, but attachment can be rejected.
Ownership delegation
ERC7695 clearly separates being the Owner from having the authority to exercise ownership rights. This is the concept behind Ownership Delegation.
In a conventional ERC721, approve and setApprovalForAll grant operational authority to others, but the Owner remains the owner.
The Owner therefore retains authority and may still perform unintended operations.
Ownership Delegation goes beyond granting permission by transferring the ownership rights themselves to another account for a specified period. During delegation, even the Owner cannot exercise ownership rights. Those rights automatically return to the Owner when the delegation expires.
This design can prevent problems such as the following.
- The Owner transfers the NFT to another account without authorization while it serves as collateral.
- The Owner uses ownership rights to change the state during an active delegation.
Delegation is also established in two steps: an offer followed by acceptance.
This helps prevent accidents caused by specifying an incorrect address.
If delegation needs to end before expiration, the delegatee can call stopOwnershipDelegation.
Integration with the transfer mechanism
ERC7695 also extends the behavior of NFT transfers. This design aims to balance user experience and security.
When an NFT is transferred, the following operations take place internally.
| Operation | Purpose |
|---|---|
| Clear ownership delegation | Prevent the new owner from inheriting a previous delegation |
| Detach all contexts | Completely reset the previous owner's usage contexts |
Corresponding events (OwnershipDelegationStopped and ContextDetached) are deliberately not emitted for these operations. This prioritizes lower gas costs and simpler processing.
The state is nevertheless reset, preserving trustlessness.
Compatibility
ERC7695 is backward-compatible with ERC721.
Basic ERC721 NFT behavior, including ownership, transfers, and approvals, is retained. The functionality introduced by ERC7695 is an extension and does not break existing ERC721-compatible tools or marketplaces.
This allows gradual adoption.
- Use the NFT as a regular ERC721.
- Use the ERC7695 extensions only where needed.
This is a practical standard designed to coexist with the existing ecosystem.
Security
Detachment waiting period
Because ERC7695 allows an NFT to be used in multiple contexts, the timing of when the token can be detached is particularly important.
The contract deployer must first set an appropriate maximum detachment waiting period through maxDetachingDuration.
This acts as a safety limit for the NFT as a whole.
Each context manager (Controller) then sets an appropriate detachingDuration for the intended use case without exceeding that maximum.
This mechanism is needed to prevent abuse by the Owner. If the detachment waiting period is extremely short or unrestricted, the following actions become possible.
- List a large number of NFTs on marketplaces or dApps.
- Transfer them to other Owners in a short period.
- Disrupt usage rights and rating systems.
Setting a maximum and a waiting period prevents NFTs from being immediately withdrawn from their commitments and helps maintain a healthy ecosystem.
Duplicate token use
ERC7695 allows multiple contexts for a single NFT, but that flexibility also introduces risks.
When creating and operating a new context, the Controller needs to be aware of other contexts already associated with the NFT and design the application to prevent duplicate usage.
Consider the following example.
- An NFT is locked in a rental context within a game.
- A separate delegation context is created in the same game.
- The same NFT is consequently used twice within the game.
Even though the contexts are distinct, this can constitute misuse in the application itself.
The following designs can help avoid this problem.
- Treat rental and delegation as one common context.
- Restrict new contexts so they cannot be used simultaneously with existing ones.
ERC7695 provides flexibility, but the Controller is responsible for how the contexts are combined.
Buffer period for ownership delegation
When building a system based on ownership delegation, the delegation period must include a sufficient buffer.
A buffer of at least maxDetachingDuration seconds is recommended.
This is necessary because contexts can lock the NFT.
Consider a concrete example.
- The maximum detachment waiting period is seven days.
- The delegation period is only three days.
- There is a contract for collateralized lending.
If the Owner locks the NFT in a related context immediately after withdrawing funds, the NFT cannot be recovered or transferred before the delegation period expires.
As a result, the system cannot secure the NFT and may be vulnerable to abuse. The delegation period must therefore be long enough to account for the worst-case lock period, and timing must be treated as a security requirement.
Verifying the callback caller
When implementing IERC7695ContextCallback, it is important to always verify the msg.sender of callback functions.
The reason is simple: a malicious third party may impersonate a legitimate callback caller.
The implementation needs to establish the following assumptions.
- Is the NFT contract the caller?
- Or is the caller a particular preapproved Controller contract?
Without this check, an unauthorized external contract may call the callback function directly and trigger unintended operations.
Recommended usage patterns
Rental
Rental is a representative use case for ERC7695. Consider the following scenario.
- A (Owner) owns an NFT.
- B (User) wants to use the NFT to play a particular game.
The NFT is attached to a rental context, and B is assigned as the User. Because the Owner does not change, holder benefits and rights remain with A.
The locking mechanism can also prevent unauthorized transfers of the NFT during the rental period.
Mortgage
In collateralized systems, there is a demand for using an NFT while it serves as collateral.
ERC7695 makes it possible to use an NFT as collateral while also using it in another context, such as a rental. This enables flexible financial models such as the following.
- A (Owner) borrows funds using the NFT as collateral.
- B (Lender) earns interest.
- The NFT may generate additional income through rentals or similar uses.
Such a design can make mortgage systems more attractive and bring in a wider range of participants.
Risks for token owners
Phishing attacks
ERC7695 allows the Owner to delegate ownership rights to another account. This is powerful functionality, but it also introduces phishing risks.
A malicious third party may deceive the Owner into executing startDelegateOwnership and assigning the attacker as the delegatee.
This risk is fundamentally similar to that of approve or setApprovalForAll.
The Owner must therefore understand that delegation transfers significant authority before performing the operation.
Risk of losing ownership rights
When integrating with collateral or other financial contracts, the Owner temporarily delegates ownership rights to the contract.
The following points require attention.
| Consideration | Reason |
|---|---|
| Is the delegation period excessively long? | Rights do not return until expiration |
| Is there a way to end delegation early? | Prevents unexpected restrictions |
| Are contract administrators secure? | Ownership rights may be exercised if an administrator or operator is compromised |
In particular, long-term delegation with no termination mechanism can lead to an effective loss of ownership rights.
ERC7695 provides a flexible mechanism, but using it safely requires both owners and developers to understand the risks and design and operate their systems accordingly.
Citation
Duc Tho Tran (@ducthotran2010), "ERC-7695: Ownership Delegation and Context for ERC-721 [DRAFT]," Ethereum Improvement Proposals, no. 7695, April 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7695.
Conclusion
This article examined ERC7695, which proposes a mechanism for delegating NFT usage rights to another user without changing the owner. I hope it was helpful.
If you have any questions, feel free to contact me via Twitter DM using the link below.
I also share information on the following platforms, so feel free to explore those as well.



