ERC-7204 · Draft · ERC · 2023-06-21
ERC-7204: Contract wallet management token
A draft interface that moves fungible-token approvals and transfers into the user's smart contract wallet, so the wallet, not each token contract, decides who may spend what.
What problem does it solve?
With ERC-20, allowances live inside every token contract. If you approve a protocol, that permission is stored in the token, and you have to visit each token separately to review or revoke it. An externally-owned account (EOA) has no code of its own, so it cannot add rules such as "only this much per day" or "only until Friday".
Smart contract wallets (for example those built on ERC-4337) do have code and storage. ERC-7204 proposes using that programmability to manage token permissions inside the wallet itself, so approval policy is set and enforced by the user's account rather than by whatever logic each token happens to have.
How it works
The wallet contract implements a small interface (IERC7204) and ERC-165:
| Function | Purpose |
|---|---|
tokenApprove(asset, spender, value) |
Let spender move up to value of token asset out of the wallet |
tokenAllowance(asset, spender) |
Read the remaining wallet-level allowance |
tokenApproveForAll(spender, approved) |
Grant or revoke permission over all tokens in the wallet |
tokenIsApproveForAll(spender) |
Check the "all tokens" flag |
tokenTransfer(asset, to, value) |
Send tokens; calls asset.transfer() internally |
Two events, TokenApproval and TokenApprovalForAll, record changes.
The key rule is in tokenTransfer: if the caller is the wallet itself, the transfer simply goes through; if the caller is anyone else, the wallet must check and decrement the allowance it keeps. Because the wallet calls the token's plain transfer, the token never needs an ERC-20 allowance for the spender at all.
The spec also suggests (optionally) batch approvals and transfers, hooks before and after tokenTransfer, and a tokenReceive function.
Sample code
A minimal wallet-side allowance check (owner logic and ERC-165 omitted):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC20 { function transfer(address to, uint256 v) external returns (bool); }
contract MiniWallet {
event TokenApproval(address indexed asset, address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) private _allow; // asset => spender => value
function tokenApprove(address asset, address spender, uint256 value) external returns (bool) {
require(msg.sender == address(this), "only wallet");
_allow[asset][spender] = value;
emit TokenApproval(asset, address(this), spender, value);
return true;
}
function tokenAllowance(address asset, address spender) external view returns (uint256) {
return _allow[asset][spender];
}
function tokenTransfer(address asset, address to, uint256 value) external returns (bool) {
if (msg.sender != address(this)) {
uint256 a = _allow[asset][msg.sender];
require(a >= value, "allowance");
_allow[asset][msg.sender] = a - value;
}
return IERC20(asset).transfer(to, value);
}
}
Things to know
- Status is Draft: the interface may still change and there is no established adoption.
- The spec's own text still contains TODO placeholders, and its Security Considerations section is empty, so review any implementation carefully.
- It only governs tokens transferred through the wallet's
tokenTransfer. Any ERC-20approveyou granted directly on a token contract still applies independently. - The companion proposal for NFTs is ERC-7564.