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.

Background

ERC-4546 proposes routing token deposits through a shared contract so users do not need to approve each application separately.

This article explains and expands on the proposal below.

I also cover other EIPs here.

Overview

The Wrapped Deposit Contract deposits assets on behalf of a user. The introduction describes Ether, ERC-20 tokens, and ERC-721 tokens, and the interface below also covers ERC-1155 tokens.

A user authorizes the wrapper once for the applicable asset and allowance. They can then use it to deposit assets into different compatible applications while the authorization remains sufficient.

Motivation

Depositing tokens into a dApp can be costly or require a broader approval than a user is comfortable granting. Common options include the following.

  • Send a separate approve transaction for each ERC-20 deposit amount.
  • Grant broad authorization in advance. For ERC-20 this can mean granting a large allowance through approve. NFT standards expose a separate operator approval method, setApprovalForAll.

The first option adds a step and incurs gas each time. The second allows a spender or operator to act over a wider set of assets or amounts. Both flows are difficult to explain to new users, and users have to repeat them for different applications.

The Wrapped Deposit Contract provides a reusable deposit flow.

Specification

Deployment and requirements

The Wrapped Deposit Contract should be deployed at a designated address, for example 0x1111119a9e30bceadf9f939390293ffacef93fe9.

It must be non-upgradeable and must not allow state variables to change after deployment. It also needs to implement the following public functions.

Deposit functions

  • depositERC20(address to, address token, uint amount)
  • depositERC721(address to, address token, uint tokenId)
  • safeDepositERC721(address to, address token, uint tokenId, bytes memory data)
  • safeDepositERC1155(address to, address token, uint tokenId, uint value, bytes calldata data)
  • batchDepositERC1155(address to, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data)
  • depositEther(address to) (payable)

Each function must enforce the following checks.

  • Revert if the destination to has code size 0.
  • Call the destination's acceptance function and revert unless it returns true.
  • Revert if the asset transfer fails.

Receiving contract interfaces

Contracts that support deposits should implement the receiver interfaces they need.

ERC20Receiver.sol
interface ERC20Receiver {
  function acceptERC20Deposit(address depositor, address token, uint amount) external returns (bool);
}
ERC721Receiver.sol
interface ERC721Receiver {
  function acceptERC721Deposit(address depositor, address token, uint tokenId) external returns (bool);
}
ERC1155Receiver.sol
interface ERC1155Receiver {
  function acceptERC1155Deposit(address depositor, address token, uint tokenId, uint value, bytes calldata data) external returns (bool);
  function acceptERC1155BatchDeposit(address depositor, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data) external returns (bool);
}
EtherReceiver.sol
interface EtherReceiver {
  function acceptEtherDeposit(address depositor, uint amount) external returns (bool);
}

A receiver can choose which interfaces to implement. Assets without a matching acceptance function cannot be deposited through this flow.

Functions

depositERC20

js
function depositERC20(address to, address token, uint amount) external;

Deposits ERC-20 tokens at a specified destination. The user supplies the token and amount, and the wrapper checks whether the destination accepts the deposit before transferring the tokens. It reverts if the receiver rejects the deposit or the transfer fails.

Parameters

  • to
    • Address receiving the assets.
  • token
    • ERC-20 token contract address.
  • amount
    • Number of token units to deposit.

depositERC721

js
function depositERC721(address to, address token, uint tokenId) external;

Deposits an ERC-721 token at a specified destination. The user supplies the NFT contract and token ID. The wrapper checks acceptance before transferring the token, and reverts if the receiver rejects it or the transfer fails.

Parameters

  • to
    • Address receiving the NFT.
  • token
    • ERC-721 token contract address.
  • tokenId
    • ID of the NFT to deposit.

safeDepositERC721

js
function safeDepositERC721(address to, address token, uint tokenId, bytes memory data) external;

Safely deposits an ERC-721 token and forwards additional data to the receiver through the token transfer. The wrapper reverts if the receiver rejects the deposit or the transfer fails.

Parameters

  • to
    • Address receiving the NFT.
  • token
    • ERC-721 token contract address.
  • tokenId
    • ID of the NFT to deposit.
  • data
    • Additional data for the receiver.

safeDepositERC1155

js
function safeDepositERC1155(address to, address token, uint tokenId, uint value, bytes calldata data) external;

Safely deposits units of one ERC-1155 token ID with additional data. The wrapper reverts if the receiver rejects the deposit or the transfer fails.

Parameters

  • to
    • Address receiving the assets.
  • token
    • ERC-1155 token contract address.
  • tokenId
    • ID of the token to deposit.
  • value
    • Number of units to deposit.
  • data
    • Additional data for the receiver.

batchDepositERC1155

js
function batchDepositERC1155(address to, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data) external;

Deposits multiple ERC-1155 token IDs in a batch. The caller pairs each ID with an amount. The wrapper reverts if the receiver rejects the deposit or the transfer fails.

Parameters

  • to
    • Address receiving the assets.
  • token
    • ERC-1155 token contract address.
  • tokenIds
    • List of token IDs to deposit.
  • values
    • Amounts corresponding to those IDs.
  • data
    • Additional data for the receiver.

depositEther

js
function depositEther(address to) external payable;

Deposits native Ether. The user sends Ether with the call and the wrapper forwards it to the specified destination after checking acceptance. The wrapper reverts if the receiver refuses or the transfer fails.

Parameters

  • to
    • Address receiving the Ether.

acceptERC20Deposit

js
function acceptERC20Deposit(address depositor, address token, uint amount) external returns (bool);

Checks whether the receiver accepts an ERC-20 deposit from the depositor for the specified token and amount. The wrapper reverts if acceptance is denied or the later transfer fails.

Parameters

  • depositor
    • Address depositing the tokens.
  • token
    • ERC-20 token contract address.
  • amount
    • Number of token units to deposit.

Return value

  • bool
    • true to accept the deposit or false to reject it.

acceptERC721Deposit

js
function acceptERC721Deposit(address depositor, address token, uint tokenId) external returns (bool);

Checks whether the receiver accepts an ERC-721 deposit from the depositor for the specified token contract and ID. It returns true on acceptance and false on refusal.

Parameters

  • depositor
    • Address depositing the NFT.
  • token
    • ERC-721 token contract address.
  • tokenId
    • ID of the NFT to deposit.

Return value

  • bool
    • true to accept the deposit or false to reject it.

acceptERC1155Deposit

js
function acceptERC1155Deposit(address depositor, address token, uint tokenId, uint value, bytes calldata data) external returns (bool);

Checks whether the receiver accepts a deposit of one ERC-1155 token ID given the depositor, token contract, amount, and additional data. It returns true on acceptance and false on refusal.

Parameters

  • depositor
    • Address depositing the tokens.
  • token
    • ERC-1155 token contract address.
  • tokenId
    • ID of the token to deposit.
  • value
    • Number of units to deposit.
  • data
    • Additional data for the receiver.

Return value

  • bool
    • true to accept the deposit or false to reject it.

acceptERC1155BatchDeposit

js
function acceptERC1155BatchDeposit(address depositor, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data) external returns (bool);

Checks whether the receiver accepts a batch of ERC-1155 tokens given the depositor, token contract, IDs, amounts, and additional data. It returns true on acceptance and false on refusal.

Parameters

  • depositor
    • Address depositing the tokens.
  • token
    • ERC-1155 token contract address.
  • tokenIds
    • List of token IDs to deposit.
  • values
    • Amounts corresponding to those IDs.
  • data
    • Additional data for the receiver.

Return value

  • bool
    • true to accept the batch or false to reject it.

acceptEtherDeposit

js
function acceptEtherDeposit(address depositor, uint amount) external returns (bool);

Checks whether the receiver accepts an Ether deposit from the specified depositor in the specified amount. It returns true on acceptance and false on refusal.

Parameters

  • depositor
    • Address depositing the Ether.
  • amount
    • Amount of Ether to deposit, in wei.

Return value

  • bool
    • true to accept the deposit or false to reject it.

Rationale

The Wrapped Deposit Contract centralizes token transfer logic. Once a user has approved the wrapper for a token, they can deposit it into multiple compatible contracts without separately approving each of them.

  • Users grant transfer permission to the wrapper instead of trusting every receiving contract with an allowance.
  • Receiving contracts implement the relevant acceptance hooks while the wrapper takes care of initiating token transfers.

This can also make the deposit flow easier to explain. An application can tell a user that enabling the shared deposit contract lets them use the same token with other compatible apps.

Compatibility

ERC-4546 can coexist with existing approval flows. A receiving contract needs the appropriate acceptance function, such as acceptERC20Deposit, to support wrapped deposits.

  • An upgradeable receiving contract can add the appropriate acceptance functions.
  • It can continue to support direct deposits for existing users while offering the Wrapped Deposit Contract to new users.

An upgradeable receiver can therefore offer both methods.

Reference Implementation

The example is reproduced from the source. Its ERC-1155 callbacks pass the recipient address (to) as the token argument, which differs from the declared receiver interface.

js
pragma solidity ^0.7.0;

interface ERC20Receiver {
  function acceptERC20Deposit(address depositor, address token, uint amount) external returns (bool);
}

interface ERC721Receiver {
  function acceptERC721Deposit(address depositor, address token, uint tokenId) external returns (bool);
}

interface ERC1155Receiver {
  function acceptERC1155Deposit(address depositor, address token, uint tokenId, uint value, bytes calldata data) external returns (bool);
  function acceptERC1155BatchDeposit(address depositor, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data) external returns (bool);
}

interface EtherReceiver {
  function acceptEtherDeposit(address depositor, uint amount) external returns (bool);
}

interface IERC20 {
  function transferFrom(address sender, address recipient, uint amount) external returns (bool);
}

interface IERC721 {
  function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
  function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes memory data) external payable;
}

interface IERC1155 {
  function safeTransferFrom(address _from, address _to, uint _id, uint _value, bytes calldata _data) external;
  function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;
}

contract WrappedDeposit {
  function depositERC20(address to, address token, uint amount) public {
    _assertContract(to);
    require(ERC20Receiver(to).acceptERC20Deposit(msg.sender, token, amount));
    bytes memory data = abi.encodeWithSelector(
      IERC20(token).transferFrom.selector,
      msg.sender,
      to,
      amount
    );
    (bool success, bytes memory returndata) = token.call(data);
    require(success);
    // backward compat for tokens incorrectly implementing the transfer function
    if (returndata.length > 0) {
      require(abi.decode(returndata, (bool)), "ERC20 operation did not succeed");
    }
  }

  function depositERC721(address to, address token, uint tokenId) public {
    _assertContract(to);
    require(ERC721Receiver(to).acceptERC721Deposit(msg.sender, token, tokenId));
    IERC721(token).transferFrom(msg.sender, to, tokenId);
  }

  function safeDepositERC721(address to, address token, uint tokenId, bytes memory data) public {
    _assertContract(to);
    require(ERC721Receiver(to).acceptERC721Deposit(msg.sender, token, tokenId));
    IERC721(token).safeTransferFrom(msg.sender, to, tokenId, data);
  }

  function safeDepositERC1155(address to, address token, uint tokenId, uint value, bytes calldata data) public {
    _assertContract(to);
    require(ERC1155Receiver(to).acceptERC1155Deposit(msg.sender, to, tokenId, value, data));
    IERC1155(token).safeTransferFrom(msg.sender, to, tokenId, value, data);
  }

  function batchDepositERC1155(address to, address token, uint[] calldata tokenIds, uint[] calldata values, bytes calldata data) public {
    _assertContract(to);
    require(ERC1155Receiver(to).acceptERC1155BatchDeposit(msg.sender, to, tokenIds, values, data));
    IERC1155(token).safeBatchTransferFrom(msg.sender, to, tokenIds, values, data);
  }

  function depositEther(address to) public payable {
    _assertContract(to);
    require(EtherReceiver(to).acceptEtherDeposit(msg.sender, msg.value));
    (bool success, ) = to.call{value: msg.value}('');
    require(success, "nonpayable");
  }

  function _assertContract(address c) private view {
    uint size;
    assembly {
      size := extcodesize(c)
    }
    require(size > 0, "noncontract");
  }
}

Security Considerations

Keep the wrapper small

The Wrapped Deposit Contract should be as small and straightforward as possible. A contract that an engineer can understand in a few minutes is easier to review and audit, reducing the chance that bugs go unnoticed.

Receiving contracts must verify the caller

When a receiving contract processes an acceptance callback, it must verify that msg.sender is the Wrapped Deposit Contract. Without this check, a direct call could be mistaken for a genuine deposit. The check ensures the receiver only accepts deposits through the intended wrapper.

Citation

Justice Hudson (@jchancehud), "ERC-4546: Wrapped Deposits [DRAFT]," Ethereum Improvement Proposals, no. 4546, December 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4546.

Conclusion

ERC-4546 proposes a shared wrapper that can send deposits into multiple apps using one authorization, rather than requiring users to approve each app individually.

Questions are welcome via direct message.

Twitter @cardene777

You can find more of my work at these links.

https://chaldene.net/