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 ERC-7204, which proposes new mechanisms for token approval and transfer in contract wallets.

This explanation translates, summarizes, and expands on the original proposal.

I have also written about other EIPs.

Abstract

The proposal focuses on managing token assets through contract wallets. Because contract wallets are programmable, they can provide more adaptable, secure, and efficient asset-management mechanisms.

The proposal introduces the following functions:

  • tokenTransfer
    • Transfers tokens to a specified address.
  • tokenApprove
    • Authorizes a specified address to spend up to a given amount of a token on the wallet's behalf.
    • This can be used to grant another party permission to spend tokens.
  • tokenApproveForAll
    • Allows a specified address to manage all tokens covered by the wallet's approval mechanism.
    • This is useful when managing multiple token assets.
  • tokenIsApproveForAll
    • Checks whether an address has been granted approval to manage all such tokens.
  • tokenAllowance
    • Returns how many tokens a spender is still authorized to spend.

These functions provide more flexible control over token transactions and asset management. For example, when authorizing payment to a service, a wallet can use tokenApprove to grant that service permission to spend a specified amount. Alternatively, tokenTransfer can send tokens directly to a friend or another wallet.

The goal is to give users more control over token management by taking advantage of programmable contract wallets.

Motivation

The proposal introduces a new approach to managing token assets through contract wallets.

What is a contract wallet?

Unlike a traditional EOA wallet, a smart contract wallet can store state and contain executable code. This makes the wallet programmable and enables more flexible operations.

Account abstraction (AA) is a related approach to building programmable accounts. ERC-7204 could be used as an extension to ERC-4337 or as a wallet plugin.

For more about ERC-4337, see the following article.

[ERC4337] Implementing account abstraction without protocol changes

Goals of the proposal

  • Self-management of assets
    • Let users configure and manage token approvals (approve) and allowances (allowance) in their own contract wallets rather than solely in token contracts. This is intended to mitigate some risks of conventional ERC-20 approvals.
  • Additional functionality
    • tokenTransfer
      • Verify the authorized amount when initiating a transaction through a smart wallet or an external account.
    • tokenApprove, tokenAllowance, tokenApproveForAll, tokenIsApproveForAll
      • Allow a wallet to manage approvals for individual tokens or all tokens covered by the wallet's mechanism.
  • Batch operations
    • Allow users to choose batch approvals or batch transfers.
  • Hooks
    • Allow users to add custom hooks before or after tokenTransfer, improving extensibility.
  • Optional tokenReceive implementation
    • Allow users to customize how the wallet receives tokens.

Compatibility

The original proposal refers to support for a simple-token ERC-X interface and compatibility with ERC-20, aiming to support management across token assets. Support for a specific NFT interface still depends on the wallet's implementation.

About ERC-X

The Japanese article also discusses ERCx, a service from Runtime Verification that provides tools for developing, testing, and checking the compliance and security of token contracts such as ERC-20, ERC-721, and ERC-1155.

ERCx goes beyond requirements stated in Ethereum Improvement Proposals by incorporating security properties designed by auditors. It offers custom security test suites for standards including ERC-20, ERC-4626, ERC-721, and ERC-1155, and produces structured reports grouping token properties by what they evaluate and why they matter.

This testing service is distinct from the token-interface terminology in the ERC-7204 proposal.

For more about ERC-721, see the following article.

https://chaldene.net/erc721

For more about ERC-1155, see the following article.

https://chaldene.net/erc1155

For more about ERC-4626, see the following article.

[ERC4626] Understanding tokenized vaults and yield-bearing shares

The proposal aims to provide more flexible and secure asset management through contract wallets. Users can customize wallet behavior, potentially mitigate some risks of conventional ERC-20 approvals, and extend the operations available to them.

Specification

Contracts conforming to this standard must implement the ERC-165 interface.

For more about ERC-165, see the following article.

[ERC165] Checking whether a contract supports a particular interface

ts
/// @title ERC-7204 
/// @dev See https://eips.ethereum.org/EIPS/eip-7204
/// @dev Note: the ERC-165 identifier for this interface is 0xf73edcda
pragma solidity ^0.8.20;

interface IERC7204 /* is ERC165 */ {

    /**
     * @notice Used to notify listeners that owner has granted approval to the user to manage assets tokens.
     * @param asset Address of the token
     * @param owner Address of the account that has granted the approval for token‘s assets
     * @param spender Address of the spender
     * @param value The amount allowed to spend
     */
    event TokenApproval(
        address indexed asset,
        address indexed owner, 
        address indexed spender, 
        uint256 value
    );

    /**
     * @notice Used to notify listeners that owner has granted approval to the spender to manage all token .
     * @param asset Address of the token
     * @param owner Address of the account that has granted the approval for token‘s assets
     * @param approved approve all token
     */
    event TokenApprovalForAll(
        address indexed owner, 
        address indexed spender,
        bool approved
    );

    /**
     * @notice Approve token
     * @dev Allows spender address to withdraw from your account multiple times, up to the value amount.
     * @dev If this function is called again it overwrites the current allowance with value.
     * @dev Emits an {TokenApproval} event.
     * @param asset Address of the token
     * @param spender Address of the spender
     * @param value The amount allowed to spend
     * @return success The bool value returns whether the approve is successful
     */
    function tokenApprove(address asset, address spender, uint256 value) 
        external 
        returns (bool success);

    /**
     * @notice read token allowance value
     * @param asset Address of the token
     * @param spender Address of the spender
     * @return remaining The asset amount which spender is still allowed to withdraw from owner.
     */
    function tokenAllowance(address asset, address spender) 
        external
        view
        returns (uint256 remaining);

    /**
     * @notice Approve all token
     * @dev Allows spender address to withdraw from your wallet all token.
     * @dev Emits an {TokenApprovalForAll} event.
     * @param spender Address of the spender
     * @param approved Approved all tokens
     * @return success The bool value returns whether the approve is successful
     */
    function tokenApproveForAll(address spender, bool approved) 
        external 
        returns (bool success);

    /**
     * @notice read spender approved value
     * @param spender Address of the spender
     * @return approved Whether to approved spender all tokens
     */
    function tokenIsApproveForAll(address spender) 
        external
        view
        returns (bool approved);

    /**
     * @notice Transfer token
     * @dev must call asset.transfer() inside the function
     * @dev If the caller is not wallet self, must verify the allowance and update the allowance value
     * @param asset Address of the token
     * @param to Address of the receive
     * @param value The transaction amount
     * @return success The bool value returns whether the transfer is successful
     */
    function tokenTransfer(address asset, address to, uint256 value) 
        external 
        returns (bool success); 
}

tokenApprove

javascript
function tokenApprove(address asset, address spender, uint256 value) 
    external 
    returns (bool success);

Overview

Authorizes a specified address to spend up to a given amount of a particular token.

Details

tokenApprove allows a specified spender to withdraw up to value units of an asset from the wallet. Calling this function again overwrites the current allowance with the new value.

The operation emits a TokenApproval event.

Arguments

  • asset
    • The token contract address.
  • spender
    • The address authorized to spend the token.
  • value
    • The amount the spender is authorized to use.

Return value

  • success
    • A bool indicating whether approval succeeded.

tokenAllowance

javascript
function tokenAllowance(address asset, address spender) 
    external
    view
    returns (uint256 remaining);

Overview

Queries a spender's remaining allowance for a particular token.

Details

tokenAllowance returns the amount of an asset that a spender is still authorized to withdraw. This lets callers determine how much of the token the spender can still use.

Arguments

  • asset
    • The token contract address.
  • spender
    • The spender's address.

Return value

  • remaining
    • The amount the spender is still authorized to withdraw.

tokenApproveForAll

javascript
function tokenApproveForAll(address spender, bool approved) 
    external 
    returns (bool success);

Overview

Sets whether a specified address is authorized to spend all tokens covered by the wallet's approval mechanism.

Details

tokenApproveForAll sets whether the specified spender has broad approval, according to the approved flag. The operation emits a TokenApprovalForAll event.

Arguments

  • spender
    • The address being granted or denied approval.
  • approved
    • A bool indicating whether to grant approval for all tokens.

Return value

  • success
    • A bool indicating whether the operation succeeded.

tokenIsApproveForAll

javascript
function tokenIsApproveForAll(address spender) 
    external
    view
    returns (bool approved);

Overview

Checks whether an address has approval to spend all tokens covered by the wallet's approval mechanism.

Details

tokenIsApproveForAll determines whether a specified spender has broad token approval. Applications can use it to check whether an address has been granted this permission.

Arguments

  • spender
    • The spender's address.

Return value

  • approved
    • A bool indicating whether the spender has approval for all tokens.

tokenTransfer

javascript
function tokenTransfer(address asset, address to, uint256 value) 
    external 
    returns (bool success);

Overview

Transfers tokens to a specified recipient.

Details

tokenTransfer transfers an asset to the to address. The wallet must call asset.transfer() internally. If the caller is not the wallet itself, the wallet must verify the applicable authorization and update the allowance as required.

Arguments

  • asset
    • The address of the token being transferred.
  • to
    • The recipient's address.
  • value
    • The amount of tokens being transferred.

Return value

  • success
    • A bool indicating whether the transfer succeeded.

Rationale

Improved approval mechanism

Differences from conventional approvals

In a conventional ERC-20 system, an EOA interacts directly with the token contract to grant approval. The proposed tokenApprove and tokenApproveForAll functions move approval management into the wallet contract, allowing the wallet to implement its own authorization policies.

Security

This design aims to mitigate risks such as excessive token approvals by moving approval control into the user's programmable wallet. Its actual security depends on the wallet's implementation and authorization rules; granting approval for all tokens is itself a broad permission.

Programmability

Wallet implementations can provide advanced policies, including conditional or time-limited approvals. tokenApproveForAll also allows a wallet-wide approval setting rather than separate approval calls on individual ERC-20 token contracts.

Optimized transfer process

Efficiency and security

tokenTransfer gives callers a consistent wallet-level entry point for token transfers, with the aim of improving transaction management and security.

Flexibility

Wallet implementations can incorporate custom logic (hooks) before and after a transfer. Such hooks can perform additional security checks or actions tailored to a user's requirements.

Batch operation support

Improved efficiency

Wallets can support multiple approval or transfer operations in a batch, potentially improving transaction efficiency.

User experience

Batch operations can simplify the management of multiple assets and improve the experience of users with large portfolios.

Together, these improvements aim to give users more precise, efficient, and secure control over token assets. The optional features described here require implementation support beyond the base interface.

Backward compatibility

This ERC is designed to be compatible with ERC-4337 and can be used as an extension to it.

Citation

Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms), "ERC-7204: Contract wallet management token [DRAFT]," Ethereum Improvement Proposals, no. 7204, June 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7204.

Conclusion

ERC-7204 proposes wallet-level approval and transfer mechanisms for contract wallets, allowing programmable accounts to manage token permissions and asset movements.

If you have questions, feel free to contact me via Twitter.

Twitter @cardene777

I also share technical content on the following platforms.

https://chaldene.net/