ERC-5507 · Final · ERC · 2022-08-19
ERC-5507: Refundable Tokens
Adds a standard refund interface to ERC-20, ERC-721 and ERC-1155 sales: buyers can return tokens for ETH until a deadline block, after which the creator can claim the escrowed funds.
What problem does it solve?
Token and NFT launches often take buyers' ETH up front and give no recourse if the project disappears ("rug pull"). Some projects promised refunds, but each implemented them differently, so wallets and marketplaces could not show or trigger them.
ERC-5507 standardizes a refund window for initial sales. Funds stay in escrow until a predetermined block; before then, holders can hand tokens back and get ETH. The spec also mentions consumer-protection rules such as refund periods for online purchases as motivation.
How it works
There is one extension per token standard, each detectable via ERC-165:
| Extension | ERC-165 ID | refund takes |
|---|---|---|
| ERC-20 Refund | 0xf0ca2917 |
amount |
| ERC-721 Refund | 0xe97f3c83 |
tokenId |
| ERC-1155 Refund | 0x94029f5c |
tokenId, amount |
Each has the same shape:
refund(...): the caller returns their own tokens and receives ETH.refundFrom(from, ...): an approved operator refunds someone else's tokens; the ETH goes tomsg.sender(useful for marketplaces or DEXs).refundOf(...): ETH (in wei) paid back per token, or per whole token unit for ERC-20.refundDeadlineOf(...): the first block at which refunds are no longer possible.Refund/RefundFromevents.
ERC-721 and ERC-1155 also have optional batch versions that succeed or fail as a whole. Deadlines use block numbers rather than timestamps, which the spec considers more reliable.
Sample code
A minimal refundable ERC-721 (OpenZeppelin v5), following checks-effects-interactions:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract RefundableNFT is ERC721 {
uint256 public constant PRICE = 0.05 ether;
uint256 public immutable refundDeadline; // first block with no refunds
uint256 private nextId;
constructor(uint256 refundBlocks) ERC721("Refundable", "RFD") {
refundDeadline = block.number + refundBlocks;
}
function mint() external payable {
require(msg.value == PRICE, "price");
_safeMint(msg.sender, nextId++);
}
function refundOf(uint256) external pure returns (uint256) { return PRICE; }
function refundDeadlineOf(uint256) external view returns (uint256) { return refundDeadline; }
function refund(uint256 tokenId) external {
require(block.number < refundDeadline, "refund closed");
require(ownerOf(tokenId) == msg.sender, "not owner");
_burn(tokenId); // effects first
(bool ok, ) = msg.sender.call{value: PRICE}(""); // interaction last
require(ok, "transfer failed");
}
// Owner withdrawal after refundDeadline omitted for brevity.
}
Things to know
- Status is Final.
- Re-entrancy is the main risk: destroy or reclaim tokens before sending ETH.
refundOfcan differ per token; a buyer who acquired tokens on a secondary market at a different price still receives the contract's refund amount.- The sample omits
supportsInterface,refundFromand the owner's withdrawal; production code needs all of them and an audit.