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 ERC6997, a proposal to introduce a validation step for NFT transfers and approvals to help prevent unauthorized transfers out of a wallet.
This article translates, summarizes, and expands on the proposal below.
As of January 11, 2024, ERC6997 was at the Review stage.
I have also written about other EIPs.
Overview
This proposal extends ERC721 with a validation mechanism designed to help prevent wallet draining, or unauthorized removal of assets from a wallet. Under conventional ERC721, transfer and approval operations take effect when the corresponding transaction executes successfully. Under this extension, these operations ordinarily remain pending until validation, rather than taking effect immediately. A transfer or approval must therefore undergo a verification process before it changes ownership or grants permission, subject to the exception for previously approved operators described below. This adds a security layer against unauthorized transactions and asset theft. Smart contracts implement the validation mechanism and can use it to detect suspicious activity or postpone transfers until specified conditions are met.
For an introduction to ERC721, see the following article.
Motivation
Giving users full responsibility for their data is both a strength and a weakness of blockchain systems. NFT theft is a significant concern. Countermeasures such as keeping NFTs in cold wallets can make them less convenient to use.
Adding a validation step before transfers and approvals allows smart contract developers to build anti-theft mechanisms for NFTs. One example is a system in which a dedicated validator address authorizes smart contract transactions. The validator can be connected to a dApp where users inspect pending validation requests for their NFTs and approve legitimate requests.
Giving the validator address only the power to validate transactions can improve security: for owner-initiated operations, an attacker would ordinarily need to compromise both the owner's account and the validator account to steal an NFT. A validation step can therefore make NFT management and use safer, provided the validator is independent of the owner's compromised credentials and existing approvals are managed safely.
Specification
ERC721-compliant contracts may implement this Ethereum Improvement Proposal.
Operations that change NFT ownership, such as transferFrom and safeTransferFrom, must ordinarily create a pending TransferValidation and emit ValidateTransfer without immediately transferring ownership.
Likewise, operations that grant authority over NFTs, such as approve and setApprovalForAll, must create a pending ApprovalValidation and emit ValidateApproval without activating the approval.
When an already approved account other than the owner initiates a transfer, the contract must execute it directly without another validation step. This exception accommodates existing marketplaces that rely on approvals to move NFTs.
When validating a TransferValidation or ApprovalValidation, the contract must set the valid field to true and must not validate the same request again.
Validating a TransferValidation is intended to execute the pending transfer and change NFT ownership. The specification also mentions enabling an approval in this requirement.
Validating an ApprovalValidation activates the requested approval.
Contract interface
interface IERC6997 {
struct TransferValidation {
// The address of the owner.
address from;
// The address of the receiver.
address to;
// The token Id.
uint256 tokenId;
// Whether is a valid transfer.
bool valid;
}
struct ApprovalValidation {
// The address of the owner.
address owner;
// The approved address.
address approve;
// The token Id.
uint256 tokenId;
// Wether is a total approvement.
bool approveAll;
// Whether is a valid approve.
bool valid;
}
/**
* @dev Emitted when a new transfer validation has been requested.
*/
event ValidateTransfer(address indexed from, address to, uint256 indexed tokenId, uint256 indexed transferValidationId);
/**
* @dev Emitted when a new approval validation has been requested.
*/
event ValidateApproval(address indexed owner, address approve, uint256 tokenId, bool indexed approveAll, uint256 indexed approvalValidationId);
/**
* @dev Returns true if this contract is a validator ERC721.
*/
function isValidatorContract() external view returns (bool);
/**
* @dev Returns the transfer validation struct using the transfer ID.
*
*/
function transferValidation(uint256 transferId) external view returns (TransferValidation memory);
/**
* @dev Returns the approval validation struct using the approval ID.
*
*/
function approvalValidation(uint256 approvalId) external view returns (ApprovalValidation memory);
/**
* @dev Return the total amount of transfer validations created.
*
*/
function totalTransferValidations() external view returns (uint256);
/**
* @dev Return the total amount of transfer validations created.
*
*/
function totalApprovalValidations() external view returns (uint256);
}TransferValidation
struct TransferValidation {
address from;
address to;
uint256 tokenId;
bool valid;
}Overview
A structure containing validation information for an NFT transfer.
Details
This structure defines the data used to validate a transfer. It records the owner's address, recipient's address, token ID, and whether the transfer request has been validated.
Parameters
address from- Address of the current token owner.
address to- Address receiving the token.
uint256 tokenId- ID of the token.
bool valid- Boolean indicating whether the transfer request has been validated.
ApprovalValidation
struct ApprovalValidation {
address owner;
address approve;
uint256 tokenId;
bool approveAll;
bool valid;
}Overview
A structure containing validation information for an NFT approval.
Details
This structure defines the data used to validate an approval. It records the owner's address, the account being approved, the token ID, whether approval concerns all tokens, and whether the approval request has been validated.
Parameters
address owner- Address of the token owner.
address approve- Address being approved.
uint256 tokenId- ID of the token.
bool approveAll- Boolean indicating approval for all tokens.
bool valid- Boolean indicating whether the approval request has been validated.
ValidateTransfer
event ValidateTransfer(address indexed from, address to, uint256 indexed tokenId, uint256 indexed transferValidationId);Overview
An event emitted when a new transfer validation is requested.
Details
The event records a transfer validation request on-chain and provides the associated information.
Parameters
address indexed from- Address of the current token owner.
address to- Address receiving the token.
uint256 indexed tokenId- ID of the token.
uint256 indexed transferValidationId- ID of the transfer validation request.
ValidateApproval
event ValidateApproval(address indexed owner, address approve, uint256 tokenId, bool indexed approveAll, uint256 indexed approvalValidationId);Overview
An event emitted when a new approval validation is requested.
Details
The event records an approval validation request on-chain and provides the associated information.
Parameters
address indexed owner- Address of the token owner.
address approve- Address being approved.
uint256 tokenId- ID of the token.
bool indexed approveAll- Boolean indicating approval for all tokens.
uint256 indexed approvalValidationId- ID of the approval validation request.
isValidatorContract
function isValidatorContract() external view returns (bool);Overview
Checks whether the contract is a validator-enabled ERC721 contract.
Details
isValidatorContract indicates whether the contract exposes the functionality associated with this validation extension.
Return value
bool- Returns
truefor a validator-enabled ERC721 contract andfalseotherwise.
- Returns
transferValidation
function transferValidation(uint256 transferId) external view returns (TransferValidation memory);Overview
Returns the TransferValidation structure associated with a specified transfer validation ID.
Details
transferValidation retrieves the validation data for the supplied transfer validation ID.
Arguments
uint256 transferId- ID of the transfer validation request to retrieve.
Return value
TransferValidation- Transfer validation information associated with the specified ID.
approvalValidation
function approvalValidation(uint256 approvalId) external view returns (ApprovalValidation memory);Overview
Returns the ApprovalValidation structure associated with a specified approval validation ID.
Details
approvalValidation retrieves the validation data for the supplied approval validation ID.
Arguments
uint256 approvalId- ID of the approval validation request to retrieve.
Return value
ApprovalValidation- Approval validation information associated with the specified ID.
totalTransferValidations
function totalTransferValidations() external view returns (uint256);Overview
Returns the total number of transfer validation requests created.
Details
totalTransferValidations reports how many transfer validation requests have been created so far.
Return value
uint256- Total number of transfer validation requests created.
totalApprovalValidations
function totalApprovalValidations() external view returns (uint256);Overview
Returns the total number of approval validation requests created.
Details
totalApprovalValidations reports how many approval validation requests have been created so far.
Return value
uint256- Total number of approval validation requests created.
The specification requires isValidatorContract() to be implemented as public.
This makes it callable by external entities and other contracts, as well as internally.
transferValidation(uint256 transferId) and approvalValidation(uint256 approveId) may be implemented as public or external.
A public function can be called internally or externally, whereas an external function is exposed through the external contract interface and is not directly callable as an internal function.
These functions retrieve the validation information for a specific transfer or approval.
totalTransferValidations() and totalApprovalValidations() may be implemented as pure or view according to the specification.
A pure function neither reads nor modifies contract state.
A view function may read state but must not modify it.
The functions return the total counts of transfer and approval validations, respectively. An implementation that stores these counters in contract state must read them using view rather than pure.
Additional details
Universality
The standard defines validation functionality but does not prescribe how to use it. Validation itself is handled internally, and implementers can decide how the requests are managed. For example, users might manage their requests through a dApp connected to a validator address. The validator could apply to all NFTs or only to particular users. The extension could also be implemented as a wrapper around existing ERC721 contracts, allowing one-to-one conversion of existing NFTs.
Extensibility
The standard defines validation functions but leaves the validation system unspecified. Third-party protocols can determine how to invoke those functions. This allows different implementations and applications, giving developers flexibility in how they use the standard.
Compatibility
This extension of ERC721 is compatible with the existing operations except transferFrom, safeTransferFrom, approve, and setApprovalForAll.
The affected operations are overridden to create validation requests instead of immediately changing ownership or activating approvals, except for transfers initiated by an already approved non-owner account.
Implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "./IERC6997.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
/**
* @dev Implementation of ERC6997
*/
contract ERC6997 is IERC6997, ERC721 {
// Mapping from transfer ID to transfer validation
mapping(uint256 => TransferValidation) private _transferValidations;
// Mapping from approval ID to approval validation
mapping(uint256 => ApprovalValidation) private _approvalValidations;
// Total number of transfer validations
uint256 private _totalTransferValidations;
// Total number of approval validations
uint256 private _totalApprovalValidations;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_){
}
/**
* @dev Returns true if this contract is a validator ERC721.
*/
function isValidatorContract() public pure returns (bool) {
return true;
}
/**
* @dev Returns the transfer validation struct using the transfer ID.
*
*/
function transferValidation(uint256 transferId) public view override returns (TransferValidation memory) {
require(transferId < _totalTransferValidations, "ERC6997: invalid transfer ID");
TransferValidation memory v = _transferValidation(transferId);
return v;
}
/**
* @dev Returns the approval validation struct using the approval ID.
*
*/
function approvalValidation(uint256 approvalId) public view override returns (ApprovalValidation memory) {
require(approvalId < _totalApprovalValidations, "ERC6997: invalid approval ID");
ApprovalValidation memory v = _approvalValidation(approvalId);
return v;
}
/**
* @dev Return the total amount of transfer validations created.
*
*/
function totalTransferValidations() public view override returns (uint256) {
return _totalTransferValidations;
}
/**
* @dev Return the total amount of approval validations created.
*
*/
function totalApprovalValidations() public view override returns (uint256) {
return _totalApprovalValidations;
}
/**
* @dev Returns the transfer validation of the `transferId`. Does NOT revert if transfer doesn't exist
*/
function _transferValidation(uint256 transferId) internal view virtual returns (TransferValidation memory) {
return _transferValidations[transferId];
}
/**
* @dev Returns the approval validation of the `approvalId`. Does NOT revert if transfer doesn't exist
*/
function _approvalValidation(uint256 approvalId) internal view virtual returns (ApprovalValidation memory) {
return _approvalValidations[approvalId];
}
/**
* @dev Validate the transfer using the transfer ID.
*
*/
function _validateTransfer(uint256 transferId) internal virtual {
TransferValidation memory v = transferValidation(transferId);
require(!v.valid, "ERC6997: the transfer is already validated");
address from = v.from;
address to = v.to;
uint256 tokenId = v.tokenId;
super._transfer(from, to, tokenId);
_transferValidations[transferId].valid = true;
}
/**
* @dev Validate the approval using the approval ID.
*
*/
function _validateApproval(uint256 approvalId) internal virtual {
ApprovalValidation memory v = approvalValidation(approvalId);
require(!v.valid, "ERC6997: the approval is already validated");
if(!v.approveAll) {
require(v.owner == ownerOf(v.tokenId), "ERC6997: The token have a new owner");
super._approve(v.approve, v.tokenId);
}
else {
super._setApprovalForAll(v.owner, v.approve, true);
}
_approvalValidations[approvalId].valid = true;
}
/**
* @dev Create a transfer petition of `tokenId` from `from` to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {TransferValidate} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
require(ERC721.ownerOf(tokenId) == from, "ERC6997: transfer from incorrect owner");
require(to != address(0), "ERC6997: transfer to the zero address");
if(_msgSender() == from) {
TransferValidation memory v;
v.from = from;
v.to = to;
v.tokenId = tokenId;
_transferValidations[_totalTransferValidations] = v;
emit ValidateTransfer(from, to, tokenId, _totalTransferValidations);
_totalTransferValidations++;
} else {
super._transfer(from, to, tokenId);
}
}
/**
* @dev Create an approval petition from `to` to operate on `tokenId`
*
* Emits an {ValidateApproval} event.
*/
function _approve(address to, uint256 tokenId) internal override virtual {
ApprovalValidation memory v;
v.owner = ownerOf(tokenId);
v.approve = to;
v.tokenId = tokenId;
_approvalValidations[_totalApprovalValidations] = v;
emit ValidateApproval(v.owner, to, tokenId, false, _totalApprovalValidations);
_totalApprovalValidations++;
}
/**
* @dev If approved is true create an approval petition from `operator` to operate on
* all of `owner` tokens, if not remove `operator` from operate on all of `owner` tokens
*
* Emits an {ValidateApproval} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal override virtual {
require(owner != operator, "ERC6997: approve to caller");
if(approved) {
ApprovalValidation memory v;
v.owner = owner;
v.approve = operator;
v.approveAll = true;
_approvalValidations[_totalApprovalValidations] = v;
emit ValidateApproval(v.owner, operator, 0, true, _totalApprovalValidations);
_totalApprovalValidations++;
}
else {
super._setApprovalForAll(owner, operator, approved);
}
}
}Security
As defined in the specification, operations that change NFT ownership or grant authority over an NFT ordinarily create a pending TransferValidation or ApprovalValidation rather than immediately transferring ownership or activating approval.
Validation of TransferValidation and ApprovalValidation must be protected according to the security requirements of the particular system.
For example, a system might have a dedicated validator address responsible for approving transactions.
Another approach would let each user choose their own validator address.
In either case, no address should be able to validate a TransferValidation or ApprovalValidation without authorization under the chosen system.
This strengthens the security of NFT transfers and approvals.
Previously approved operators remain an important exception: they can transfer NFTs directly under the proposal, so a validation layer does not eliminate the risk of compromised or malicious operators. The reference code must also be reviewed against the application's access-control and validation requirements before production use.
References
Eduard López i Fina (@eduardfina), "ERC-6997: ERC-721 with transaction validation step. [DRAFT]," Ethereum Improvement Proposals, no. 6997, May 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6997.
Conclusion
This article examined ERC6997, a proposal to add a validation step to NFT transfers and approvals to help prevent unauthorized transfers out of wallets.
If you have questions, feel free to contact me via Twitter direct message.
I also write on the following platforms.


