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 ERC4973, a proposal for an interface that binds non-transferable NFTs to Ethereum accounts, much like legendary items are bound to characters in World of Warcraft.
This article translates, summarizes, and expands on the proposal linked below.
As of September 9, 2023, ERC4973 was at the Review stage.
Overview
A proposed standard API for Account-Bound Tokens (ABTs)
An ABT (Account-Bound Token) is a non-fungible token managed by a smart contract and associated with a single account. ABTs have no standard interface for transferring tokens. This Ethereum Improvement Proposal (EIP) defines basic functionality for issuing, assigning, revoking, and tracking ABTs.
Motivation
In the popular MMORPG World of Warcraft, game designers deliberately excluded certain items from the in-game auction house and marketplace. Keeping their prices from being publicly quoted made these items difficult to acquire.
Thunderfury, Blessed Blade of the Windseeker, a legendary item in vanilla WoW, is one such example. Acquiring the Essence of the Firelord, a material required to craft the sword, involved participating in a 40-player raid.
Once obtained, the sword became permanently bound to the character's soul, making it impossible to trade or sell it between player characters.
In other words, the price of Thunderfury amounted to the combined social costs of completing difficult quests with friends and guild members. Seeing another player with Thunderfury served as evidence that its owner had defeated Ragnaros.
Players in World of Warcraft could permanently remove legendary or soulbound items such as Thunderfury from their accounts by destroying them. Players could choose whether to visibly equip or unequip these items, allowing them to display their accomplishments.
The Ethereum community needs non-transferable, non-exchangeable tokens whose value is socially determined, much like soulbound items in WoW. Existing smart contracts often implicitly implement account-bound interaction rights. Standardization helps improve interoperability and on-chain data indexing.
The goal of this proposal is to enable ABTs on Ethereum.
Specification
ABTs must implement the following interfaces.
- ERC165 (
0x01ffc9a7) - ERC721Metadata from ERC721 (
0x5b5e139f)
See the following article for more on ERC165.
[ERC165] Checking Whether a Contract Supports an Interface
ABTs must not implement the following interface.
- ERC721 (
0x80ac58cd)
See the following article for more on ERC721.
An ABT recipient can always call function unequip(address _tokenId) to remove the ABT from their account.
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.6;
/// @title Account-bound tokens
/// @dev See https://eips.ethereum.org/EIPS/eip-4973
/// Note: the ERC-165 identifier for this interface is 0xeb72bb7c
interface IERC4973 {
/// @dev This emits when ownership of any ABT changes by any mechanism.
/// This event emits when ABTs are given or equipped and unequipped
/// (`to` == 0).
event Transfer(
address indexed from, address indexed to, uint256 indexed tokenId
);
/// @notice Count all ABTs assigned to an owner
/// @dev ABTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param owner An address for whom to query the balance
/// @return The number of ABTs owned by `address owner`, possibly zero
function balanceOf(address owner) external view returns (uint256);
/// @notice Find the address bound to an ERC4973 account-bound token
/// @dev ABTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// @param tokenId The identifier for an ABT.
/// @return The address of the owner bound to the ABT.
function ownerOf(uint256 tokenId) external view returns (address);
/// @notice Removes the `uint256 tokenId` from an account. At any time, an
/// ABT receiver must be able to disassociate themselves from an ABT
/// publicly through calling this function. After successfully executing this
/// function, given the parameters for calling `function give` or
/// `function take` a token must be re-equipable.
/// @dev Must emit a `event Transfer` with the `address to` field pointing to
/// the zero address.
/// @param tokenId The identifier for an ABT.
function unequip(uint256 tokenId) external;
/// @notice Creates and transfers the ownership of an ABT from the
/// transaction's `msg.sender` to `address to`.
/// @dev Throws unless `bytes signature` represents a signature of the
// EIP-712 structured data hash
/// `Agreement(address active,address passive,bytes metadata)` expressing
/// `address to`'s explicit agreement to be publicly associated with
/// `msg.sender` and `bytes metadata`. A unique `uint256 tokenId` must be
/// generated by type-casting the `bytes32` EIP-712 structured data hash to a
/// `uint256`. If `bytes signature` is empty or `address to` is a contract,
/// an EIP-1271-compatible call to `function isValidSignatureNow(...)` must
/// be made to `address to`. A successful execution must result in the
/// `event Transfer(msg.sender, to, tokenId)`. Once an ABT exists as an
/// `uint256 tokenId` in the contract, `function give(...)` must throw.
/// @param to The receiver of the ABT.
/// @param metadata The metadata that will be associated to the ABT.
/// @param signature A signature of the EIP-712 structured data hash
/// `Agreement(address active,address passive,bytes metadata)` signed by
/// `address to`.
/// @return A unique `uint256 tokenId` generated by type-casting the `bytes32`
/// EIP-712 structured data hash to a `uint256`.
function give(address to, bytes calldata metadata, bytes calldata signature)
external
returns (uint256);
/// @notice Creates and transfers the ownership of an ABT from an
/// `address from` to the transaction's `msg.sender`.
/// @dev Throws unless `bytes signature` represents a signature of the
/// EIP-712 structured data hash
/// `Agreement(address active,address passive,bytes metadata)` expressing
/// `address from`'s explicit agreement to be publicly associated with
/// `msg.sender` and `bytes metadata`. A unique `uint256 tokenId` must be
/// generated by type-casting the `bytes32` EIP-712 structured data hash to a
/// `uint256`. If `bytes signature` is empty or `address from` is a contract,
/// an EIP-1271-compatible call to `function isValidSignatureNow(...)` must
/// be made to `address from`. A successful execution must result in the
/// emission of an `event Transfer(from, msg.sender, tokenId)`. Once an ABT
/// exists as an `uint256 tokenId` in the contract, `function take(...)` must
/// throw.
/// @param from The origin of the ABT.
/// @param metadata The metadata that will be associated to the ABT.
/// @param signature A signature of the EIP-712 structured data hash
/// `Agreement(address active,address passive,bytes metadata)` signed by
/// `address from`.
/// @return A unique `uint256 tokenId` generated by type-casting the `bytes32`
/// EIP-712 structured data hash to a `uint256`.
function take(address from, bytes calldata metadata, bytes calldata signature)
external
returns (uint256);
/// @notice Decodes the opaque metadata bytestring of an ABT into the token
/// URI that will be associated with it once it is created on chain.
/// @param metadata The metadata that will be associated to an ABT.
/// @return A URI that represents the metadata.
function decodeURI(bytes calldata metadata) external returns (string memory);
}See ERC721 for the metadata JSON schema.
https://chaldene.net/erc721#st-toc-h-8
EIP-712 typed structured data hashing and byte-array signatures
Calling functions such as give(...) or take(...) requires a byte-array signature (signature) created using EIP712.
Tested Node.js reference implementations are provided in index.mjs, index_test.mjs, and package.json.
In Solidity, the byte-array signature can be constructed as follows.
bytes32 r = 0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90;
bytes32 s = 0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064;
uint8 v = 27;
bytes memory signature = abi.encodePacked(r, s, v);Additional considerations
Interface
Account-Bound Tokens (ABTs) provide a minimal, straightforward interface while maximizing backward compatibility.
Wallet providers and marketplaces widely support ERC721 tokens. By using the ERC721Metadata interface together with ERC165 for feature detection, they can readily support ABTs.
If ERC721 implementers correctly use the ERC165 supportsInterface(bytes4 interfaceID) function, they can detect that the ERC721 tracking and transfer interface (interface ID 0x80ac58cd) is not implemented and avoid displaying token transfer options in the user interface.
Because ABTs support the ERC721Metadata extension of ERC721, wallets and marketplaces can display account-bound tokens without modification.
Other approaches to implementing account-bound tokens are possible, such as reverting every transfer function. ABTs have the advantage of supporting feature detection through ERC165.
The interface also exposes function unequip(address _tokenId) so an ABT owner can call it at any time.
Exception handling
Because ABTs cannot be transferred between accounts, a user whose private key is compromised or changed may lose their association with a token. In some circumstances, this may be desirable. ABT implementers should therefore provide reissuance and revocation processes to address such situations. A strictly decentralized, permissionless, and censorship-resistant reissuance process is recommended.
However, this proposal deliberately avoids standardizing exception handling for compromised or changed user keys.
If implementers want account-bound tokens to be shared across different accounts, for example to avoid losing access when a key is compromised, the proposal suggests issuing the tokens to contract accounts with multisignature functionality.
Provenance indexing
ABTs can be indexed by tracking occurrences of the Transfer(address indexed from, address indexed to, uint256 indexed tokenId) event.
As with ERC721, the event records movement between two accounts when both from and to are nonzero addresses.
A token is unequipped by setting the to address to the zero address.
There is no mint operation in which from is set to the zero address.
To prevent contracts from impersonating other issuers by deliberately emitting misleading Transfer events, indexers must verify that the transaction sender matches the from value in the Transfer event.
A misleading Transfer event can create the appearance that token ownership has changed, potentially confusing users or facilitating fraud.
Backward compatibility
The proposal adopts functionality from ERC165 and ERC721Metadata.
The objective is to maximize backward compatibility with ERC721.
It deliberately uses ERC721 terminology and functions such as ownerOf(...) and balanceOf(...) to make the interface familiar to users and developers accustomed to ERC20 and ERC721 implementations.
It also reuses the widely implemented Transfer event signature for indexers.
Reference implementation
The complete source code is available in the following GitHub repository.
abstract contract ERC4973 is EIP712, ERC165, IERC721Metadata, IERC4973 {
using BitMaps for BitMaps.BitMap;
BitMaps.BitMap private _usedHashes;
string private _name;
string private _symbol;
mapping(uint256 => address) private _owners;
mapping(uint256 => string) private _tokenURIs;
mapping(address => uint256) private _balances;
constructor(string memory name_, string memory symbol_, string memory version)
EIP712(name_, version)
{
_name = name_;
_symbol = symbol_;
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns (bool)
{
return interfaceId == type(IERC721Metadata).interfaceId
|| interfaceId == type(IERC4973).interfaceId
|| super.supportsInterface(interfaceId);
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(_exists(tokenId), "tokenURI: token doesn't exist");
return _tokenURIs[tokenId];
}
function unequip(uint256 tokenId) public virtual override {
require(msg.sender == ownerOf(tokenId), "unequip: sender must be owner");
_usedHashes.unset(tokenId);
_burn(tokenId);
}
function balanceOf(address owner)
public
view
virtual
override
returns (uint256)
{
require(owner != address(0), "balanceOf: address zero is not a valid owner");
return _balances[owner];
}
function ownerOf(uint256 tokenId) public view virtual returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ownerOf: token doesn't exist");
return owner;
}
function give(address to, bytes calldata metadata, bytes calldata signature)
external
virtual
returns (uint256)
{
require(msg.sender != to, "give: cannot give from self");
uint256 tokenId = _safeCheckAgreement(msg.sender, to, metadata, signature);
string memory uri = decodeURI(metadata);
_mint(msg.sender, to, tokenId, uri);
_usedHashes.set(tokenId);
return tokenId;
}
function take(address from, bytes calldata metadata, bytes calldata signature)
external
virtual
returns (uint256)
{
require(msg.sender != from, "take: cannot take from self");
uint256 tokenId = _safeCheckAgreement(msg.sender, from, metadata, signature);
string memory uri = decodeURI(metadata);
_mint(from, msg.sender, tokenId, uri);
_usedHashes.set(tokenId);
return tokenId;
}
function decodeURI(bytes calldata metadata)
public
virtual
returns (string memory)
{
return string(metadata);
}
function _safeCheckAgreement(
address active,
address passive,
bytes calldata metadata,
bytes calldata signature
)
internal
virtual
returns (uint256)
{
bytes32 hash = _getHash(active, passive, metadata);
uint256 tokenId = uint256(hash);
require(
SignatureChecker.isValidSignatureNow(passive, hash, signature),
"_safeCheckAgreement: invalid signature"
);
require(!_usedHashes.get(tokenId), "_safeCheckAgreement: already used");
return tokenId;
}
function _getHash(address active, address passive, bytes calldata metadata)
internal
view
returns (bytes32)
{
bytes32 structHash =
keccak256(abi.encode(AGREEMENT_HASH, active, passive, keccak256(metadata)));
return _hashTypedDataV4(structHash);
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
function _mint(address from, address to, uint256 tokenId, string memory uri)
internal
virtual
returns (uint256)
{
require(!_exists(tokenId), "mint: tokenID exists");
_balances[to] += 1;
_owners[tokenId] = to;
_tokenURIs[tokenId] = uri;
emit Transfer(from, to, tokenId);
return tokenId;
}
function _burn(uint256 tokenId) internal virtual {
address owner = ownerOf(tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
delete _tokenURIs[tokenId];
emit Transfer(owner, address(0), tokenId);
}
}constructor
constructor(string memory name_, string memory symbol_, string memory version)
EIP712(name_, version)
{
_name = name_;
_symbol = symbol_;
}Overview
- The contract constructor.
- Sets the token name, symbol, and version.
Details
- An initialization function called when the contract is deployed.
Parameters
name_- String representing the token name.
symbol_- String representing the token symbol.
version- String representing the token version.
supportsInterface
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns (bool)
{
return interfaceId == type(IERC721Metadata).interfaceId
|| interfaceId == type(IERC4973).interfaceId
|| super.supportsInterface(interfaceId);
}Overview
- Checks whether an interface is supported.
Details
- Determines whether the specified interface is supported.
Parameters
interfaceId- Byte sequence representing the interface ID to check.
Return value
- Returns
trueif the interface is supported, andfalseotherwise.
name
function name() public view virtual override returns (string memory) {
return _name;
}Overview
- Retrieves the token name.
Details
- Retrieves the name as a string.
Return value
- Returns a string representing the token name.
symbol
function symbol() public view virtual override returns (string memory) {
return _symbol;
}Overview
- Retrieves the token symbol.
Details
- Retrieves the symbol as a string.
Return value
- Returns a string representing the token symbol.
tokenURI
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(_exists(tokenId), "tokenURI: token doesn't exist");
return _tokenURIs[tokenId];
}Overview
- Retrieves the token's Uniform Resource Identifier (URI).
Details
- Retrieves the URI of the specified token as a string.
- Reverts with an error if the token does not exist.
Parameters
tokenId- ID of the token whose URI is requested.
Return value
- Returns a string representing the token URI.
unequip
function unequip(uint256 tokenId) public virtual override {
require(msg.sender == ownerOf(tokenId), "unequip: sender must be owner");
_usedHashes.unset(tokenId);
_burn(tokenId);
}Overview
- Unequips a token.
Details
- A caller who does not own the token cannot unequip it.
- Unequipping resets the token's hash and removes the token.
Parameters
tokenId- ID of the token to unequip.
balanceOf
function balanceOf(address owner)
public
view
virtual
override
returns (uint256)
{
require(owner != address(0), "balanceOf: address zero is not a valid owner");
return _balances[owner];
}Overview
- Retrieves the token balance of the specified address.
Details
- Reverts with an error if the address is the zero address.
Parameters
owner- Address whose balance is requested.
Return value
- Returns an integer representing the token balance of the specified address.
ownerOf
function ownerOf(uint256 tokenId) public view virtual returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ownerOf: token doesn't exist");
return owner;
}Overview
- Retrieves the owner of the specified token.
Details
- Reverts with an error if the token does not exist.
Parameters
tokenId- ID of the token whose owner is requested.
Return value
- Returns the address of the token owner.
give
function give(address to, bytes calldata metadata, bytes calldata signature)
external
virtual
returns (uint256)
{
require(msg.sender != to, "give: cannot give from self");
uint256 tokenId = _safeCheckAgreement(msg.sender, to, metadata, signature);
string memory uri = decodeURI(metadata);
_mint(msg.sender, to, tokenId, uri);
_usedHashes.set(tokenId);
return tokenId;
}Overview
- Gives a token to another address.
Details
- The caller cannot give a token to themselves.
- Before issuing the token, the function verifies the signature and decodes the URI (Uniform Resource Identifier).
Parameters
to- Address receiving the token.
metadata- Token metadata represented as a byte sequence.
signature- Signature data.
Return value
- Returns an integer representing the ID of the issued token.
take
function take(address from, bytes calldata metadata, bytes calldata signature)
external
virtual
returns (uint256)
{
require(msg.sender != from, "take: cannot take from self");
uint256 tokenId = _safeCheckAgreement(msg.sender, from, metadata, signature);
string memory uri = decodeURI(metadata);
_mint(from, msg.sender, tokenId, uri);
_usedHashes.set(tokenId);
return tokenId;
}Overview
- Receives a token from another address.
Details
- The caller cannot take a token from themselves.
- Before issuing the token, the function verifies the signature and decodes the URI.
Parameters
from- Address from which the token is received.
metadata- Token metadata represented as a byte sequence.
signature- Signature data.
Return value
- Returns an integer representing the ID of the issued token.
decodeURI
function decodeURI(bytes calldata metadata)
public
virtual
returns (string memory)
{
return string(metadata);
}Overview
- Decodes metadata and retrieves it as a string.
Details
- Converts the supplied byte-array metadata into a string and returns it.
Parameters
metadata- Byte sequence containing the metadata to decode.
Return value
- Returns the metadata as a string.
_safeCheckAgreement
function _safeCheckAgreement(
address active,
address passive,
bytes calldata metadata,
bytes calldata signature
)
internal
virtual
returns (uint256)
{
bytes32 hash = _getHash(active, passive, metadata);
uint256 tokenId = uint256(hash);
require(
SignatureChecker.isValidSignatureNow(passive, hash, signature),
"_safeCheckAgreement: invalid signature"
);
require(!_usedHashes.get(tokenId), "_safeCheckAgreement: already used");
return tokenId;
}Overview
- Checks the agreement and generates a token ID.
Details
- Generates a token ID based on the sender (
active), recipient (passive), metadata, and signature verification. - Verifies the signature and checks whether the same token ID is already in use.
Parameters
active- Address of the sender.
passive- Address of the recipient.
metadata- Token metadata represented as a byte sequence.
signature- Signature data.
Return value
- Returns an integer representing the generated token ID.
_getHash
function _getHash(address active, address passive, bytes calldata metadata)
internal
view
returns (bytes32)
{
bytes32 structHash =
keccak256(abi.encode(AGREEMENT_HASH, active, passive, keccak256(metadata)));
return _hashTypedDataV4(structHash);
}Overview
- Generates a hash.
Details
- Generates a hash from the sender (
active), recipient (passive), and metadata.
Parameters
active- Address of the sender.
passive- Address of the recipient.
metadata- Token metadata represented as a byte sequence.
Return value
- Returns the generated hash as a byte sequence (bytes32).
_exists
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}Overview
- Checks whether a token exists.
Details
- Determines whether the specified token ID exists.
Parameters
tokenId- Integer representing the token ID to check.
Return value
- Returns
trueif the token exists, andfalseotherwise.
_mint
function _mint(address from, address to, uint256 tokenId, string memory uri)
internal
virtual
returns (uint256)
{
require(!_exists(tokenId), "mint: tokenID exists");
_balances[to] += 1;
_owners[tokenId] = to;
_tokenURIs[tokenId] = uri;
emit Transfer(from, to, tokenId);
return tokenId;
}Overview
- Mints a token.
Details
- Issues a new token and sets its owner and URI.
Parameters
from- Address issuing the token.
to- Address that will own the token.
tokenId- Integer representing the ID of the token to mint.
uri- URI (Uniform Resource Identifier) associated with the token.
Return value
- Returns an integer representing the ID of the minted token.
_burn
function _burn(uint256 tokenId) internal virtual {
address owner = ownerOf(tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
delete _tokenURIs[tokenId];
emit Transfer(owner, address(0), tokenId);
}Overview
- Burns (removes) a token.
Details
- Identifies the owner of the specified token ID and burns the token.
Parameters
tokenId- Integer representing the ID of the token to burn.
Return value
- None.
Security considerations
There are no security considerations directly associated with implementing this standard.
References
Tim Daubenschütz (@TimDaub), "ERC-4973: Account-bound Tokens [DRAFT]," Ethereum Improvement Proposals, no. 4973, April 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4973.
Further reading
What are Account-bound tokens?
Conclusion
This article examined ERC4973, a proposal for an interface that binds non-transferable NFTs to Ethereum accounts, much like legendary items are bound to characters in World of Warcraft.
If you have questions, feel free to contact me via direct message on Twitter.
I also publish articles on other platforms:



