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 ERC5507, a proposed standard for adding refund functionality to ERC20, ERC721, and ERC1155 tokens.
This article translates, summarizes, and expands on the following proposal.
Overview
This ERC proposes adding refund functionality to primary sales of ERC20, ERC721, and ERC1155 tokens.
For more on ERC20, see the following article.
For more on ERC721, see the following article.
For more on ERC1155, see the following article.
Under this mechanism, the proceeds of token purchases are held in a third-party-managed escrow account until a predetermined period expires. During that period, buyers can return the tokens they purchased and receive their money back.
For example, if a buyer purchases a token but the project does not progress as expected, they can return the token using the refund function and recover the funds they invested.
Motivation
The NFT and token ecosystem faces the problem of rug pulls, in which developers run away with users' funds. A reliable way to mitigate this problem is needed. Introducing refunds can protect purchasers and improve the credibility of creators.
A standardized interface for these situations offers the following benefits.
- It can make it easier to accommodate EU distance-selling consumer protection rules, which generally provide a 14-day withdrawal period for qualifying online purchases. Applicability to particular token sales depends on the relevant legal conditions.
Distance Selling Regulation Distance-selling rules are consumer protection regulations applicable primarily in the European Union (EU). They concern goods and services purchased outside a physical store, such as through online shops, mail orders, or telephone sales, and provide consumers with rights to return or cancel qualifying purchases.
In the EU, distance-selling rules generally give consumers who purchase goods or services online a right to withdraw within 14 days; for goods, this period generally begins on delivery. For eligible purchases, consumers can return goods without providing a reason and receive a refund. The objective is to mitigate the risks inherent in distance selling, where consumers make purchase decisions without inspecting the goods in person.
Distance-selling regulations also impose duties on sellers to improve transparency and help consumers transact with confidence. For example, sellers must provide clear information about goods, contractual terms, and cancellation policies.
- Interoperability with NFT-related applications such as portfolio browsers and marketplaces becomes possible.
- NFT marketplaces can display a badge indicating that an NFT is still refundable or suggest a refund instead of listing it for sale.
- Decentralized exchanges can offer refunds when doing so would yield better proceeds than a sale.
- Wallets can communicate token refund actions more clearly to users.
- This is similar to displaying a dedicated dialog for token transfers.
- DAOs can more clearly display proposals that include token refund actions.
These capabilities are intended to improve protection for NFT and token buyers and increase confidence in the market. Adoption of the standard by contracts and other tools could help create a safer and more reliable trading environment.
Specification
Implementations conforming to this standard must also implement ERC165.
For more on ERC165, see the following article.
[ERC165] Checking whether a contract supports a specific interface
ERC20 Refund Extension
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.17;
import "ERC20.sol";
import "ERC165.sol";
/// @notice Refundable ERC-20 tokens
/// @dev The ERC-165 identifier of this interface is `0xf0ca2917`
interface ERC20Refund is ERC20, ERC165 {
/// @notice Emitted when a token is refunded
/// @dev Emitted by `refund`
/// @param _from The account whose assets are refunded
/// @param _amount The amount of token (in terms of the indivisible unit) that was refunded
event Refund(
address indexed _from,
uint256 indexed _amount
);
/// @notice Emitted when a token is refunded
/// @dev Emitted by `refundFrom`
/// @param _sender The account that sent the refund
/// @param _from The account whose assets are refunded
/// @param _amount The amount of token (in terms of the indivisible unit) that was refunded
event RefundFrom(
address indexed _sender,
address indexed _from,
uint256 indexed _amount
);
/// @notice As long as the refund is active, refunds the user
/// @dev Make sure to check that the user has the token, and be aware of potential re-entrancy vectors
/// @param amount The `amount` to refund
function refund(uint256 amount) external;
/// @notice As long as the refund is active and the sender has sufficient approval, refund the tokens and send the ether to the sender
/// @dev Make sure to check that the user has the token, and be aware of potential re-entrancy vectors
/// The ether goes to msg.sender.
/// @param from The user from which to refund the assets
/// @param amount The `amount` to refund
function refundFrom(address from, uint256 amount) external;
/// @notice Gets the refund price
/// @return _wei The amount of ether (in wei) that would be refunded for a single token unit (10**decimals indivisible units)
function refundOf() external view returns (uint256 _wei);
/// @notice Gets the first block for which the refund is not active
/// @return block The first block where the token cannot be refunded
function refundDeadlineOf() external view returns (uint256 block);
}Refund
event Refund(
address indexed _from,
uint256 indexed _amount
);Overview
Emitted when tokens are refunded.
Details
The refund function triggers this event.
When tokens are refunded, the event records the account and amount associated with the refund on the blockchain.
Parameters
_from- The account whose assets were refunded.
_amount- The amount of tokens refunded, in the smallest divisible units.
RefundFrom
event RefundFrom(
address indexed _sender,
address indexed _from,
uint256 indexed _amount
);Overview
Emitted when tokens are refunded on behalf of another account.
Details
The refundFrom function triggers this event.
When someone refunds tokens from another account, the event records the caller, the account whose tokens were refunded, and the refunded amount on the blockchain.
Parameters
_sender- The account that initiated the refund.
_from- The account whose assets were refunded.
_amount- The amount of tokens refunded, in the smallest divisible units.
refund
function refund(uint256 amount) external;Overview
Refunds the user while refunds remain active.
Details
Before executing this function, check that the user holds the tokens and take care to prevent reentrancy issues.
Parameters
amount- The amount to refund.
refundFrom
function refundFrom(address from, uint256 amount) external;Overview
Refunds tokens and sends ETH to the caller if refunds are active and the caller has sufficient approval.
Details
Check that the user holds the tokens and send ETH to msg.sender, taking care to prevent reentrancy issues.
Parameters
from- The user whose assets are being refunded.
amount- The amount to refund.
refundOf
function refundOf() external view returns (uint256 _wei);Overview
Returns the refund price.
Details
Returns the amount of ether, in wei, refundable for one indivisible token unit, as defined by the token's decimal precision (10**decimals).
Returns
_wei- The refund amount for a single token unit, in
wei.
- The refund amount for a single token unit, in
refundDeadlineOf
function refundDeadlineOf() external view returns (uint256 block);Overview
Returns the first block at which refunds are no longer active.
Details
Returns the first block number at which tokens are no longer refundable.
Returns
block- The first block number at which tokens are no longer refundable.
ERC721 Refund Extension
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.17;
import "ERC721.sol";
import "ERC165.sol";
/// @notice Refundable ERC-721 tokens
/// @dev The ERC-165 identifier of this interface is `0xe97f3c83`
interface ERC721Refund is ERC721 /* , ERC165 */ {
/// @notice Emitted when a token is refunded
/// @dev Emitted by `refund`
/// @param _from The account whose assets are refunded
/// @param _tokenId The `tokenId` that was refunded
event Refund(
address indexed _from,
uint256 indexed _tokenId
);
/// @notice Emitted when a token is refunded
/// @dev Emitted by `refundFrom`
/// @param _sender The account that sent the refund
/// @param _from The account whose assets are refunded
/// @param _tokenId The `tokenId` that was refunded
event RefundFrom(
address indexed _sender,
address indexed _from,
uint256 indexed _tokenId
);
/// @notice As long as the refund is active for the given `tokenId`, refunds the user
/// @dev Make sure to check that the user has the token, and be aware of potential re-entrancy vectors
/// @param tokenId The `tokenId` to refund
function refund(uint256 tokenId) external;
/// @notice As long as the refund is active and the sender has sufficient approval, refund the token and send the ether to the sender
/// @dev Make sure to check that the user has the token, and be aware of potential re-entrancy vectors
/// The ether goes to msg.sender.
/// @param from The user from which to refund the token
/// @param tokenId The `tokenId` to refund
function refundFrom(address from, uint256 tokenId) external;
/// @notice Gets the refund price of the specific `tokenId`
/// @param tokenId The `tokenId` to query
/// @return _wei The amount of ether (in wei) that would be refunded
function refundOf(uint256 tokenId) external view returns (uint256 _wei);
/// @notice Gets the first block for which the refund is not active for a given `tokenId`
/// @param tokenId The `tokenId` to query
/// @return block The first block where token cannot be refunded
function refundDeadlineOf(uint256 tokenId) external view returns (uint256 block);
}Refund
event Refund(
address indexed _from,
uint256 indexed _tokenId
);Overview
Emitted when a token is refunded.
Details
The refund function emits this event, which is recorded on the blockchain when a token is refunded.
Parameters
_from- The account whose assets were refunded.
_tokenId- The ID of the refunded token.
RefundFrom
event RefundFrom(
address indexed _sender,
address indexed _from,
uint256 indexed _tokenId
);Overview
Emitted when a token is refunded on behalf of another account.
Details
The refundFrom function emits this event, which is recorded on the blockchain when a token is refunded on behalf of another account.
Parameters
_sender- The account that initiated the refund.
_from- The account whose assets were refunded.
_tokenId- The ID of the refunded token.
refund
function refund(uint256 tokenId) external;Overview
Refunds the user for the specified tokenId while refunds remain active.
Details
Before executing this function, check that the user holds the token and take care to prevent reentrancy issues.
Parameters
tokenId- The ID of the token to refund.
refundFrom
function refundFrom(address from, uint256 tokenId) external;Overview
Refunds the token and sends ETH to the caller if refunds are active and the caller has sufficient approval.
Details
Check that the user holds the token and send ETH to msg.sender, taking care to prevent reentrancy issues.
Parameters
from- The user whose token is being refunded.
tokenId- The ID of the token to refund.
refundOf
function refundOf(uint256 tokenId) external view returns (uint256 _wei);Overview
Returns the refund price for a particular tokenId.
Details
Returns the amount of ETH, in wei, refundable for the specified token ID.
Parameters
tokenId- The ID of the token to query.
Returns
_wei- The amount of ether refundable, in
wei.
- The amount of ether refundable, in
refundDeadlineOf
function refundDeadlineOf(uint256 tokenId) external view returns (uint256 block);Overview
Returns the first block at which refunds are no longer active for the specified tokenId.
Details
Returns the first block number at which refunds cease to be available for the specified token ID.
Parameters
tokenId- The ID of the token to query.
Returns
block- The first block number at which the token is no longer refundable.
ERC721 Batch Refund Extension (Option)
// SPDX-License-Identifier: CC0-1.0;
import "ERC721Refund.sol";
/// @notice Batch Refundable ERC-721 tokens
/// @dev The ERC-165 identifier of this interface is ``
contract ERC721BatchRefund is ERC721Refund {
/// @notice Emitted when one or more tokens are batch refunded
/// @dev Emitted by `refundBatch`
/// @param _from The account whose assets are refunded
/// @param _tokenId The `tokenIds` that were refunded
event RefundBatch(
address indexed _from,
uint256[] _tokenIds // This may or may not be indexed
);
/// @notice Emitted when one or more tokens are batch refunded
/// @dev Emitted by `refundFromBatch`
/// @param _sender The account that sent the refund
/// @param _from The account whose assets are refunded
/// @param _tokenId The `tokenId` that was refunded
event RefundFromBatch(
address indexed _sender,
address indexed _from,
uint256 indexed _tokenId
);
/// @notice As long as the refund is active for the given `tokenIds`, refunds the user
/// @dev Make sure to check that the user has the tokens, and be aware of potential re-entrancy vectors
/// These must either succeed or fail together; there are no partial refunds.
/// @param tokenIds The `tokenId`s to refund
function refundBatch(uint256[] tokenIds) external;
/// @notice As long as the refund is active for the given `tokenIds` and the sender has sufficient approval, refund the tokens and send the ether to the sender
/// @dev Make sure to check that the user has the tokens, and be aware of potential re-entrancy vectors
/// The ether goes to msg.sender.
/// These must either succeed or fail together; there are no partial refunds.
/// @param from The user from which to refund the token
/// @param tokenIds The `tokenId`s to refund
function refundFromBatch(address from, uint256[] tokenIds) external;
}RefundBatch
event RefundBatch(
address indexed _from,
uint256[] _tokenIds
);Overview
Emitted when one or more tokens are refunded in a batch.
Details
The refundBatch function emits this event, which is recorded on the blockchain when multiple tokens are refunded in a single batch.
Parameters
_from- The account whose assets were refunded.
_tokenIds- An array of refunded token IDs.
RefundFromBatch
event RefundFromBatch(
address indexed _sender,
address indexed _from,
uint256 indexed _tokenId
);Overview
Emitted when one or more tokens are refunded in a batch on behalf of another account.
Details
The refundFromBatch function emits this event, which is recorded on the blockchain when another account refunds multiple tokens in a batch on someone else's behalf.
Parameters
_sender- The account that initiated the refund.
_from- The account whose assets were refunded.
_tokenId- The ID of the refunded token.
- This parameter is indexed.
refundBatch
function refundBatch(uint256[] tokenIds) external;Overview
Refunds the user for the specified tokenIds in a batch while refunds remain active.
Details
Check that the user owns the specified tokens and take care to prevent reentrancy issues. Either all token refunds succeed or the operation fails; partial refunds are not permitted.
Parameters
tokenIds- An array of token IDs to refund.
refundFromBatch
function refundFromBatch(address from, uint256[] tokenIds) external;Overview
Refunds the specified tokenIds in a batch and sends ETH to the caller if refunds are active and the caller has sufficient approval.
Details
Check that the user owns the specified tokens and take care to prevent reentrancy issues.
Ether is sent to msg.sender.
Either all token refunds succeed or the operation fails; partial refunds are not permitted.
Parameters
from- The user whose tokens are being refunded.
tokenIds- An array of token IDs to refund.
ERC1155 Refund Extension
Refund
event Refund(
address indexed _from,
uint256 indexed _tokenId,
uint256 _amount
);Overview
Emitted when tokens are refunded.
Details
The refund function emits this event, recording the account that requested the refund, the refunded token ID, and the refunded token amount on the blockchain.
Parameters
_from- The account that requested the refund.
_tokenId- The ID of the refunded token.
_amount- The amount of tokens refunded.
RefundFrom
event RefundFrom(
address indexed _sender,
address indexed _from,
uint256 indexed _tokenId
);Overview
Emitted when tokens are refunded on behalf of another account.
Details
The refundFrom function emits this event, recording the account that initiated the refund, the account whose assets were refunded, and the refunded token ID on the blockchain.
Note that this event definition does not include the refunded token amount (_amount).
Parameters
_sender- The account that initiated the refund.
_from- The account whose assets were refunded.
_tokenId- The ID of the refunded token.
refund
function refund(uint256 tokenId, uint256 amount) external;Overview
Refunds the user for the specified tokenId while refunds remain active.
Details
Check that the user holds enough tokens and that there are no reentrancy issues. The refund is processed according to the specified token ID and amount.
Parameters
tokenId- The ID of the token to refund.
amount- The amount of tokens to refund.
refundFrom
function refundFrom(address from, uint256 tokenId, uint256 amount) external;Overview
Refunds tokens and sends ETH to the caller while refunds are active and the caller has sufficient approval.
Details
Check that the user holds enough tokens and take care to prevent reentrancy issues.
ETH is sent to msg.sender.
The refund is processed according to the user whose tokens are being refunded, the specified token ID, and the amount.
Parameters
from- The user whose tokens are being refunded.
tokenId- The ID of the token to refund.
amount- The amount of tokens to refund.
refundOf
function refundOf(uint256 tokenId) external view returns (uint256 _wei);Overview
Returns the refund price for a particular tokenId.
Details
Returns the amount of ETH, in wei, refundable per token of the specified ID.
Parameters
tokenId- The ID of the token to query.
Returns
_wei- The refund amount per token, in
wei.
- The refund amount per token, in
refundDeadlineOf
function refundDeadlineOf(uint256 tokenId) external view returns (uint256 block);Overview
Returns the first block at which refunds are no longer active for the specified tokenId.
Details
Returns the first block number at which refunds cease to be available for the specified token ID.
Parameters
tokenId- The ID of the token to query.
Returns
block- The first block number at which the token is no longer refundable.
ERC1155 Batch Refund Extension (Option)
// SPDX-License-Identifier: CC0-1.0;
import "ERC1155Refund.sol";
/// @notice Batch Refundable ERC-1155 tokens
/// @dev The ERC-165 identifier of this interface is ``
contract ERC1155BatchRefund is ERC1155Refund {
/// @notice Emitted when one or more tokens are batch refunded
/// @dev Emitted by `refundBatch`
/// @param _from The account that requested a refund
/// @param _tokenIds The `tokenIds` that were refunded
/// @param _amounts The amount of each `tokenId` that was refunded
event RefundBatch(
address indexed _from,
uint256[] _tokenIds, // This may or may not be indexed
uint256[] _amounts
);
/// @notice Emitted when one or more tokens are batch refunded
/// @dev Emitted by `refundFromBatch`
/// @param _sender The account that sent the refund
/// @param _from The account whose assets are refunded
/// @param _tokenIds The `tokenIds` that was refunded
/// @param _amounts The amount of each `tokenId` that was refunded
event RefundFromBatch(
address indexed _sender,
address indexed _from,
uint256[] _tokenId, // This may or may not be indexed
uint256[] _amounts
);
/// @notice As long as the refund is active for the given `tokenIds`, refunds the user
/// @dev Make sure to check that the user has enough tokens, and be aware of potential re-entrancy vectors
/// These must either succeed or fail together; there are no partial refunds.
/// @param tokenIds The `tokenId`s to refund
/// @param amounts The amount of each `tokenId` to refund
function refundBatch(uint256[] tokenIds, uint256[] amounts) external;
/// @notice As long as the refund is active for the given `tokenIds` and the sender has sufficient approval, refund the tokens and send the ether to the sender
/// @dev Make sure to check that the user has the tokens, and be aware of potential re-entrancy vectors
/// The ether goes to msg.sender.
/// These must either succeed or fail together; there are no partial refunds.
/// @param from The user from which to refund the token
/// @param tokenIds The `tokenId`s to refund
/// @param amounts The amount of each `tokenId` to refund
function refundFromBatch(address from, uint256[] tokenIds, uint256[] amounts external;
}RefundBatch
event RefundBatch(
address indexed _from,
uint256[] _tokenIds,
uint256[] _amounts
);Overview
Emitted when multiple tokens are refunded in a batch.
Details
The refundBatch function emits this event, recording the account that requested the refund and each refunded token ID and amount on the blockchain.
Parameters
_from- The account that requested the refund.
_tokenIds- An array of refunded token IDs.
_amounts- An array containing the refunded amount for each
tokenId.
- An array containing the refunded amount for each
RefundFromBatch
event RefundFromBatch(
address indexed _sender,
address indexed _from,
uint256[] _tokenIds,
uint256[] _amounts
);Overview
Emitted when multiple tokens are refunded in a batch on behalf of another account.
Details
The refundFromBatch function emits this event, recording the account that initiated the refund, the account whose assets were refunded, and the refunded token IDs and amounts on the blockchain.
Parameters
_sender- The account that initiated the refund.
_from- The account whose assets were refunded.
_tokenIds- An array of refunded token IDs.
- This array may be indexed.
_amounts- An array containing the refunded amount for each
tokenId.
- An array containing the refunded amount for each
refundBatch
function refundBatch(uint256[] tokenIds, uint256[] amounts) external;Overview
Refunds the user for the specified amount of each tokenId in tokenIds in a batch while refunds remain active.
Details
Check that the user holds sufficient amounts of the tokens and take care to prevent reentrancy risks. Either all refunds succeed together or they all fail; partial refunds are not performed.
Parameters
tokenIds- An array of token IDs to refund.
amounts- An array containing the amount to refund for each
tokenId.
- An array containing the amount to refund for each
refundFromBatch
function refundFromBatch(address from, uint256[] tokenIds, uint256[] amounts) external;Overview
Refunds the specified tokenIds in a batch and sends ETH to the caller if refunds are active and the caller has sufficient approval.
Details
Check that the user holds sufficient amounts of the tokens and take care to prevent reentrancy risks.
ETH is sent to msg.sender.
Either all refunds succeed together or they all fail; partial refunds are not performed.
Parameters
from- The user whose tokens are being refunded.
tokenIds- An array of token IDs to refund.
amounts- An array containing the amount to refund for each
tokenId.
- An array containing the amount to refund for each
Additional notes
The refundDeadlineOf function specifies the refund deadline using a block number.
The proposal uses block numbers rather than timestamps because it considers them more reliable for this purpose.
The function names refund, refundOf, and refundDeadlineOf follow the naming conventions of existing contract standards such as ERC20, ERC721, and ERC1155.
ERC165 facilitates interface introspection when dApps interact with contracts. Without it, dApps cannot efficiently determine whether a contract supports a particular interface.
Custom ERC20 refund currencies are not supported directly, to avoid unnecessary system complexity.
However, combining refundFrom with a DEX can provide refund functionality involving custom tokens.
Custom ERC20 tokens are not supported directly because doing so would increase system complexity. In particular, custom ERC20 tokens often have behavior or functionality beyond the standard ERC20 interface, requiring additional code to support them. Examples include tokens with custom fee models and tokens that permit transactions only under certain conditions. Handling these behaviors would require additional exception handling and security checks in the contract, increasing overall system complexity.
Combining refundFrom with a decentralized exchange (DEX) may make refunds involving custom tokens possible.
DEXs handle many different tokens and can perform token-specific processing.
When users exchange custom tokens through a DEX, the DEX can handle those tokens' special rules as part of the refund process.
This approach keeps the refundable-token contract simple while allowing the DEX to provide flexibility for custom tokens.
Batch refund functionality is optional. With the introduction of account abstraction, these batch operations may become easier in the future. However, batch refunds should still be implemented appropriately to save gas costs.
Backward compatibility
There are no backward compatibility issues.
Security considerations
The refund function presents a security risk if it can be called repeatedly in unexpected ways.
To mitigate this risk, ensure that the tokens have been properly burned before sending ETH.
Operations should follow the checks-effects-interactions pattern: perform security checks first, then update internal state, such as burning tokens, and finally interact with external accounts or contracts, such as when sending ETH.
Following this pattern mitigates reentrancy risks.
Citation
elie222 (@elie222), Gavin John (@Pandapip1), "ERC-5507: Refundable Tokens," Ethereum Improvement Proposals, no. 5507, August 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5507.
Conclusion
This article examined ERC5507, a proposed standard for adding refund functionality to ERC20, ERC721, and ERC1155 tokens.

