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 covers ERC7417, a proposal to improve compatibility and convenience by enabling bidirectional conversion between different token standards, namely ERC20 and ERC223, on Ethereum.
This explanation translates, summarizes, and expands on the following specification.
I have also written about other EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.
Overview
ERC7417 proposes a mechanism for interoperability between widely used token standards on Ethereum. Specifically, it provides a smart contract called the Token Converter, through which tokens of one standard (ERC20) can be converted to tokens of another standard (ERC223) and back again. Tokens converted to ERC223 can also be converted back to ERC20 without restrictions. This allows different standards to coexist and be used interchangeably without sacrificing compatibility with older standards.
For more about ERC223, see the following article.
[ERC223] ERC20 Tokens with ETH-Like Transfer Behavior
The user-facing conversion process is simple. When a user deposits tokens of the original standard into the Converter contract, it automatically returns tokens of the other standard to the user.
The terms used here have the following meanings.
- ERC20 / ERC223 Token specifications (interfaces) defined for Ethereum. They define the behavior of functions and events so that wallets, exchanges, and DApps can interact safely with tokens.
- Smart contract A program executed automatically on Ethereum. Code defines and enforces token issuance, transfer rules, and conversion operations.
- Token Converter The central smart contract in ERC7417. It converts deposited tokens to corresponding tokens of the other standard at a 1:1 ratio and returns them.
- Wrapper A mechanism that issues an asset in a different form, backed by the original asset. Here, it allows ERC20 and ERC223 versions of a token representing the same economic value to be wrapped and unwrapped.
sequenceDiagram
participant U as User
participant C as Token Converter
participant T20 as ERC-20 token
participant T223 as ERC-223 token
U->>C: Deposit ERC-20 tokens
C->>T20: Receive and lock
C-->>U: Send equivalent ERC-223 tokens
U->>C: Deposit ERC-223 tokens (reverse conversion)
C->>T223: Receive and lock
C-->>U: Send equivalent ERC-20 tokens
Motivation
ERC7417 aims to make it possible to upgrade token standards at any time through a dedicated smart contract. ERC20 is already the most widely adopted standard, and the absence of a clear process for migrating collectively to a new standard (here, ERC223) hinders adoption. With a Converter in place, ERC20 and ERC223 can operate in parallel and be converted in either direction whenever required.
It is also common for the same token asset to circulate across multiple chains and token standards. For example, USDT exists as ERC20 on Ethereum, TRC20 on TRON (called TRX USDT in the original text), and BEP20 on BSC, among other forms. ERC7417 aims to standardize a comparable arrangement within Ethereum mainnet itself, allowing tokens of the same value but different standards to coexist and be converted. In other words, it envisions an Ethereum-based ERC20 version of USDT and ERC223 version of USDT existing simultaneously and being freely interchangeable.
Establishing trust is also important. The proposal specifies the deployment address of the Converter contract so token developers can safely integrate with the correct Converter. A published, fixed address helps prevent accidental connections to impersonating contracts and breakdowns in interoperability.
All ERC223 tokens issued or wrapped by the Converter are expected to provide the same set of functions and return-value semantics.
This avoids incompatibilities caused by differing interpretations of the standard or variations in implementation.
For ERC20, differences in how the transfer return value is handled have been a longstanding issue.
The specification requires a Boolean return value, but three types of implementation have existed in practice.
| Category | Behavior on success | Behavior on failure |
|---|---|---|
| ① Strict return-value implementation | Returns true |
Signals failure by reverting |
| ② Permissive return-value implementation | Returns true or false |
May return false without reverting |
| ③ No return value | Returns nothing | Signals failure by reverting |
Strictly speaking, category ③ does not conform to ERC20. However, USDT on Ethereum mainnet (address: 0xdac17f958d2ee523a2206206994597c13d831ec7) uses this pattern and is central to the ecosystem, so refusing to support it simply because it is nonconforming is impractical. These historical circumstances have made implementation differences within the same standard a significant issue.
The Converter helps accommodate these differences. By providing a consistent ERC223 implementation, it allows tokens with early custom extensions or differing interpretations of the specification to be handled according to a common specification after conversion. Surrounding smart contracts, such as decentralized exchanges, can more easily treat a wrapped pair as a single asset on the assumption that the two tokens are fundamentally equivalent and convertible at any time. This enables designs that combine liquidity from different standard versions of the same asset.
Finally, the service is intended to remain in use indefinitely once deployed to Ethereum mainnet. Publishing the Converter address in the proposal lets developers refer to the canonical Converter without ambiguity and maintains a stable basis for interoperability.
Conversion flow
The process is intuitive: users direct tokens to the Converter.
- Send tokens of the source standard (for example, ERC20) to the designated Converter using its conversion flow.
- The Converter locks the received tokens and automatically sends an equivalent amount of tokens of the destination standard (for example, ERC223) to the user.
- To recover the original tokens, perform the corresponding reverse conversion (ERC223 → ERC20).
The Converter preserves value, provides a 1:1 exchange ratio, and enables reversible conversion, allowing ERC20 and ERC223 to coexist and interoperate.
Specification
System architecture
The token conversion system consists of two main components.
| Component | Description |
|---|---|
| Converter contract | The core smart contract that handles deposits, withdrawals, conversion, wrapping, and unwrapping. |
| Wrapper contract | A wrapper created for an original token, with only one wrapper per token per destination standard. |
Basic behavior of the Converter contract
Each ERC20 token has at most one ERC223 wrapper. During an ERC20 → ERC223 conversion, the Converter receives the original tokens, issues the same quantity of ERC223 tokens, and returns them to the sender. During the reverse ERC223 → ERC20 conversion, it burns the received ERC223 tokens and returns the original ERC20 tokens. The conversion ratio is always fixed at 1:1.
Converter contract
getERC20WrapperFor
function getERC20WrapperFor(address _token) public view returns (address)Retrieves the address of the ERC20 wrapper corresponding to a specified token address.
It returns the ERC20 version of the specified ERC223 token.
If no corresponding wrapper exists, it returns 0x0.
Only one ERC20 wrapper is created for each ERC223 token.
Parameters
_token- Address of the target token.
Return value
address- Address of the corresponding ERC20 wrapper, or
0x0if none exists.
- Address of the corresponding ERC20 wrapper, or
getERC223WrapperFor
function getERC223WrapperFor(address _token) public view returns (address)Returns the address of the ERC223 wrapper corresponding to the specified token.
It retrieves the ERC223 wrapper address for a specified ERC20 token.
If none exists, it returns 0x0.
Parameters
_token- Address of the original ERC20 token.
Return value
address- Address of the corresponding ERC223 wrapper.
getERC20OriginFor
function getERC20OriginFor(address _erc223Token) public view returns (address)Retrieves the original ERC20 token corresponding to the specified ERC223 wrapper.
If the given address is an ERC223 wrapper generated by the Converter, the function returns its original ERC20 token address.
If no corresponding token exists, it returns 0x0.
Parameters
_erc223Token- Address of the ERC223 wrapper.
Return value
address- Address of the original ERC20 token.
getERC223OriginFor
function getERC223OriginFor(address _erc20Token) public view returns (address)Returns the original ERC223 token corresponding to the specified ERC20 wrapper.
If the ERC20 token is a wrapper created by the Converter, the function returns the address of its original ERC223 token.
If no corresponding token exists, it returns 0x0.
Parameters
_erc20Token- Address of the ERC20 wrapper.
Return value
address- Address of the original ERC223 token.
predictWrapperAddress
function predictWrapperAddress(address _token, bool _isERC20) view external returns (address)Predicts the address of a wrapper contract that has not yet been deployed. The function uses the CREATE2 opcode to compute the wrapper address before deployment. The resulting address depends on the bytecode.
- When
_isERC20 = truePredict the ERC223 wrapper address. - When
_isERC20 = falsePredict the ERC20 wrapper address.
Parameters
_token- Address of the target token.
_isERC20- Whether the token is an ERC20 token.
Return value
address- Predicted wrapper address.
createERC223Wrapper
function createERC223Wrapper(address _erc20Token) public returns (address)Creates a new ERC223 wrapper corresponding to the specified ERC20 token.
The transaction reverts if a wrapper already exists.
Once created, the wrapper conforms to the standard ERC223 specification and also implements approve and transferFrom for compatibility.
Its standard() function returns 223 to identify the token standard.
Parameters
_erc20Token- Address of the original ERC20 token.
Return value
address- Address of the newly created ERC223 wrapper.
createERC20Wrapper
function createERC20Wrapper(address _erc223Token) public returns (address)Creates an ERC20 wrapper corresponding to a specified ERC223 token.
It reverts if a wrapper already exists.
It does not verify whether _erc223Token is actually an ERC223 token.
It is therefore technically possible to create a wrapper of the same standard accidentally.
Parameters
_erc223Token- Address of the original ERC223 token.
Return value
address- Address of the newly created ERC20 wrapper.
wrapERC20toERC223
function wrapERC20toERC223(address _ERC20token, uint256 _amount) public returns (bool)Converts ERC20 tokens into ERC223 tokens.
It uses transferFrom to withdraw ERC20 tokens from the sender and sends the same quantity of ERC223 wrapper tokens.
The original tokens are held by the Converter contract for future unwrapping.
If a wrapper does not exist, it is created automatically.
Parameters
_ERC20token- Address of the source ERC20 token.
_amount- Quantity of tokens to convert.
Return value
booltrueon success.
convertERC20
function convertERC20(address _token, uint256 _amount) public returns (bool)Automatically determines the token type and performs wrapping or unwrapping.
If the specified token is a wrapper, it executes unwrapERC20toERC223.
If it is an original token, it executes wrapERC20toERC223.
This simplifies conversion for DApps and exchanges supporting both standards.
Parameters
_token- Token address.
_amount- Quantity to convert.
Return value
booltrueon success.
isWrapper
function isWrapper(address _token) public view returns (bool)Checks whether the specified token is a wrapper created by the Converter.
Returns true if the address corresponds to a Converter-generated wrapper.
It does not distinguish between ERC20 and ERC223.
Parameters
_token- Token address.
Return value
booltrueif the token is a wrapper.
tokenReceived
function tokenReceived(address _from, uint _value, bytes memory _data) public override returns (bytes4)A handler invoked automatically when ERC223 tokens are received.
The function is invoked during an ERC223 transfer and performs the following operations depending on the received token.
- For an ERC223 wrapper generated by the Converter Return the original ERC20 tokens.
- For an original ERC223 token not registered with the Converter Create the corresponding ERC20 wrapper and send the wrapper tokens.
It returns 0x8943ec02.
Parameters
_from- Sender address.
_value- Token quantity.
_data- Additional data.
Return value
bytes4- Fixed value
0x8943ec02.
- Fixed value
extractStuckERC20
function extractStuckERC20(address _token)Recovers ERC20 tokens accidentally transferred directly to the Converter.
The Converter maintains records of legitimate conversions performed through convertERC20toERC223.
By comparing these records with balanceOf(this), it identifies tokens sent in error that can be recovered.
Parameters
_token- Address of the target token.
Token conversion procedures
Converting ERC20 → ERC223
- The user calls
approveon the ERC20 token to authorize the Converter to withdraw the specified quantity. - Wait for the
approvetransaction to be confirmed on-chain. - Call
convertERC20toERC223on the Converter contract to execute the conversion.
Converting ERC223 → ERC20
- The user sends ERC223 tokens to the Converter address using
transfer. - On receipt, the Converter automatically executes
tokenReceivedand returns ERC20 tokens to the user.
Additional considerations
Support for original ERC223 tokens
Two approaches were considered when designing the Token Converter.
| Approach | Description | Expected impact |
|---|---|---|
| 1 | Provide only one-way wrapping of existing ERC20 tokens as ERC223 tokens | New issuances would tend to assume ERC20, putting developers choosing ERC223 as the original standard at a disadvantage. |
| External contracts handling two versions of an asset, such as an AMM combining both versions into one pool, would also fail to identify an original ERC223 token paired with an ERC20 version as the same asset. | ||
| 2 | Allow creation of both ERC20 and ERC223 wrappers for an arbitrary original token | Projects choosing ERC223 as their original standard can retain ERC20 compatibility through the Converter. DEXs and pools can identify both standard versions as the same asset, improving interoperability. |
The proposal adopts approach 2 to maximize interoperability and fairness. Developers choosing ERC223 as the original standard can obtain an ERC20 version without additional development, while external services can more easily treat different standard versions as a single asset.
Supporting approve and transferFrom in ERC223 wrappers
In ERC223, the receiving contract receives a callback (tokenReceived), so ordinary deposits can safely be made using transfer alone.
This makes approve and transferFrom appear redundant in ERC223.
In practice, however, many multisigs and other contracts designed around ERC20 are already in use, and designs that receive tokens without assuming callbacks are widespread.
To prioritize ecosystem compatibility, the Converter's ERC223 wrappers also implement approve and transferFrom.
This makes the wrappers easier to use directly as reference implementations.
However, transferFrom introduces a typical concern.
If a user approves themselves and then uses transferFrom(self, contract, X) to push tokens into a contract that does not support callbacks, the assets may become inaccessible unless recovery logic exists.
approve and transferFrom are not intended as the direct mechanism for ordinary wallet transfers; they are APIs designed to allow contracts to pull tokens.
Therefore, prioritize transfer for ERC223 where possible and use approve and transferFrom only when necessary for compatibility.
Aligning ERC223 events with the existing ecosystem
A pure ERC223 implementation emits events such as the following.
// A Transfer event commonly used in pure ERC223 implementations
event Transfer(address indexed _from, address indexed _to, uint256 _value, bytes _data);Because this event has a different signature from ERC20 Transfer(address,address,uint256), blockchain explorers, wallets, and transaction history viewers may fail to recognize it.
The event itself is not essential logic that directly affects contract security or state transitions.
ERC7417 therefore prioritizes compatibility with existing tooling.
This reduces operational friction in monitoring, analytics, and accounting.
Why standard() is used to identify the standard
ERC165 can check for function signatures, but ERC20 and ERC223 expose similar sets of functions and are difficult to distinguish solely by their visible interfaces.
Actual behavior depends on the internal logic of transfer, specifically whether a callback is invoked when transferring to a contract. ERC165 alone is therefore not sufficiently precise.
For more about ERC165, see the following article.
[ERC165] Checking Whether a Contract Supports a Particular Interface
Example showing why identification is difficult
abstract contract Token {
function name() external virtual returns (string memory);
function symbol() external virtual returns (string memory);
function decimals() external virtual returns (uint8);
function transfer(address, uint256) external virtual returns (bool);
function approve(address, uint256) external virtual returns (bool);
function transferFrom(address, address, uint256) external virtual returns (bool);
}This abstract interface cannot distinguish ERC20 from ERC223 by function signatures alone. Their behavior varies according to the internal implementation.
An ERC20-style implementation is shown below.
function transfer(address _to, uint256 _amount) external virtual returns (bool) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
}An ERC223-style implementation that calls tokenReceived when the recipient is a contract is shown below.
function transfer(address _to, uint256 _amount) external virtual returns (bool) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
if (_to.isContract()) {
IERC223Recipient(_to).tokenReceived(msg.sender, _amount, hex"000000");
}
}Many tokens may not implement ERC165 at all.
The Converter therefore implements standard() returns (uint32) in the ERC223 wrappers it issues, returning 223.
Original ERC223 tokens may also implement this function to identify themselves. Tokens without it are treated as ERC20 under the operational rule.
This provides a more practical indication of the token standard than relying on ERC165 alone.
Functions used in the sample code
The following explanations organize the functions in the preceding sample code by purpose.
name
function name() external virtual returns (string memory);Retrieves the token name. Returns the full name displayed to users. Many wallets and explorers use it for display.
Return value
string memory- Token name.
symbol
function symbol() external virtual returns (string memory);Retrieves the token symbol.
Returns a short identifier used in trading screens and balance displays, such as USDT or DAI.
Return value
string memory- Token symbol.
decimals
function decimals() external virtual returns (uint8);Retrieves the number of decimal places.
Returns the scale used for user-facing display and amount conversion. 18 is common.
Return value
uint8- Number of decimal places.
transfer
function transfer(address _to, uint256 _amount) external virtual returns (bool);Sends tokens to a specified address.
Subtracts the specified amount from the sender's balance and adds it to the recipient's balance.
An ERC223-style implementation calls tokenReceived when the destination is a contract to ensure safe receipt. An ERC20-style implementation does not invoke the callback.
Parameters
_to- Recipient address.
_amount- Transfer amount.
Return value
bool- An implementation that returns
trueon success is recommended.
- An implementation that returns
approve
function approve(address _spender, uint256 _amount) external virtual returns (bool);Sets the amount a third party is authorized to withdraw on behalf of the sender.
Because of allowance overwrite race conditions and misconfiguration risks, appropriate approval procedures or permit (EIP2612) are preferable.
In ERC223, transfer is normally the safe transfer mechanism, but approve is provided for compatibility.
For more about EIP2612, see the following article.
[ERC2612] Executing ERC20 approve and transferFrom in One Transaction
Parameters
_spender- Authorized spender.
_amount- Approved amount.
Return value
booltrueon success.
transferFrom
function transferFrom(address _from, address _to, uint256 _amount) external virtual returns (bool);Allows a third party to execute a transfer based on prior approval.
Transfers tokens from the balance of _from to _to within the allowance established by approve.
For ERC223, prioritize transfer because misusing transferFrom can push assets into contracts that do not support callbacks.
Parameters
_from- Source address.
_to- Destination address.
_amount- Transfer amount.
Return value
booltrueon success.
Compatibility
ERC7417 aims to address compatibility concerns by allowing conversion between different token standards. Because ERC20 and ERC223 are interchangeable at a 1:1 ratio, existing DApps and tools can continue operating through the Converter even if they support only one standard.
The service itself has no preceding equivalent mechanism whose specification it must preserve, so it is designed without historical backward-compatibility constraints.
Reference implementation
pragma solidity =0.8.19;
library Address {
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IERC20Metadata is IERC20 {
/// @return The name of the token
function name() external view returns (string memory);
/// @return The symbol of the token
function symbol() external view returns (string memory);
/// @return The number of decimal places the token has
function decimals() external view returns (uint8);
}
abstract contract IERC223Recipient {
function tokenReceived(address _from, uint _value, bytes memory _data) public virtual returns (bytes4)
{
return 0x8943ec02;
}
}
abstract contract ERC165 {
/*
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return _supportedInterfaces[interfaceId];
}
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
abstract contract IERC223 {
function name() public view virtual returns (string memory);
function symbol() public view virtual returns (string memory);
function decimals() public view virtual returns (uint8);
function totalSupply() public view virtual returns (uint256);
function balanceOf(address who) public virtual view returns (uint);
function transfer(address to, uint value) public virtual returns (bool success);
function transfer(address to, uint value, bytes calldata data) public payable virtual returns (bool success);
event Transfer(address indexed from, address indexed to, uint value, bytes data);
}
interface standardERC20
{
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
/**
* @dev Interface of the ERC20 standard.
*/
interface IERC223WrapperToken {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function standard() external view returns (string memory);
function origin() external view returns (address);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external payable returns (bool);
function transfer(address to, uint256 value, bytes calldata data) external payable returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function mint(address _recipient, uint256 _quantity) external;
function burn(address _recipient, uint256 _quantity) external;
}
interface IERC20WrapperToken {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function standard() external view returns (string memory);
function origin() external view returns (address);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function mint(address _recipient, uint256 _quantity) external;
function burn(address _recipient, uint256 _quantity) external;
}
contract ERC20Rescue
{
// ERC20 tokens can get stuck on a contracts balance due to lack of error handling.
//
// The author of the ERC7417 can extract ERC20 tokens if they are mistakenly sent
// to the wrapper-contracts balance.
// Contact dexaran@ethereumclassic.org
address public extractor = 0x01000B5fE61411C466b70631d7fF070187179Bbf;
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function rescueERC20(address _token, uint256 _amount) external
{
safeTransfer(_token, extractor, _amount);
}
}
contract ERC223WrapperToken is IERC223, ERC165, ERC20Rescue
{
address public creator = msg.sender;
address private wrapper_for;
mapping(address account => mapping(address spender => uint256)) private allowances;
event Transfer(address indexed from, address indexed to, uint256 amount);
event TransferData(bytes data);
event Approval(address indexed owner, address indexed spender, uint256 amount);
function set(address _wrapper_for) external
{
require(msg.sender == creator);
wrapper_for = _wrapper_for;
}
uint256 private _totalSupply;
mapping(address => uint256) private balances; // List of user balances.
function totalSupply() public view override returns (uint256) { return _totalSupply; }
function balanceOf(address _owner) public view override returns (uint256) { return balances[_owner]; }
/**
* @dev The ERC165 introspection function.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IERC20).interfaceId ||
interfaceId == type(standardERC20).interfaceId ||
interfaceId == type(IERC223WrapperToken).interfaceId ||
interfaceId == type(IERC223).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev Standard ERC223 transfer function.
* Calls _to if it is a contract. Does not transfer tokens to contracts
* which do not explicitly declare the tokenReceived function.
* @param _to - transfer recipient. Can be contract or EOA.
* @param _value - the quantity of tokens to transfer.
* @param _data - metadata to send alongside the transaction. Can be used to encode subsequent calls in the recipient.
*/
function transfer(address _to, uint _value, bytes calldata _data) public payable override returns (bool success)
{
balances[msg.sender] = balances[msg.sender] - _value;
balances[_to] = balances[_to] + _value;
if (msg.value > 0)
{
(bool sent, bytes memory data) = _to.call{value: msg.value}("");
require(sent);
}
if(Address.isContract(_to)) {
IERC223Recipient(_to).tokenReceived(msg.sender, _value, _data);
}
emit Transfer(msg.sender, _to, _value, _data);
emit Transfer(msg.sender, _to, _value); // Old ERC20 compatible event. Added for backwards compatibility reasons.
return true;
}
/**
* @dev Standard ERC223 transfer function without _data parameter. It is supported for
* backwards compatibility with ERC20 services.
* Calls _to if it is a contract. Does not transfer tokens to contracts
* which do not explicitly declare the tokenReceived function.
* @param _to - transfer recipient. Can be contract or EOA.
* @param _value - the quantity of tokens to transfer.
*/
function transfer(address _to, uint _value) public override returns (bool success)
{
bytes memory _empty = hex"00000000";
balances[msg.sender] = balances[msg.sender] - _value;
balances[_to] = balances[_to] + _value;
if(Address.isContract(_to)) {
IERC223Recipient(_to).tokenReceived(msg.sender, _value, _empty);
}
emit Transfer(msg.sender, _to, _value, _empty);
emit Transfer(msg.sender, _to, _value); // Old ERC20 compatible event. Added for backwards compatibility reasons.
return true;
}
function name() public view override returns (string memory) { return IERC20Metadata(wrapper_for).name(); }
function symbol() public view override returns (string memory) { return string.concat(IERC20Metadata(wrapper_for).symbol(), "223"); }
function decimals() public view override returns (uint8) { return IERC20Metadata(wrapper_for).decimals(); }
function standard() public pure returns (uint32) { return 223; }
function origin() public view returns (address) { return wrapper_for; }
/**
* @dev Minting function which will only be called by the converter contract.
* @param _recipient - the address which will receive tokens.
* @param _quantity - the number of tokens to create.
*/
function mint(address _recipient, uint256 _quantity) external
{
require(msg.sender == creator, "Wrapper Token: Only the creator contract can mint wrapper tokens.");
balances[_recipient] += _quantity;
_totalSupply += _quantity;
}
/**
* @dev Burning function which will only be called by the converter contract.
* @param _quantity - the number of tokens to destroy. TokenConverter can only destroy tokens on it's own address.
* Only the token converter is allowed to burn wrapper-tokens.
*/
function burn(uint256 _quantity) external
{
require(msg.sender == creator, "Wrapper Token: Only the creator contract can destroy wrapper tokens.");
balances[msg.sender] -= _quantity;
_totalSupply -= _quantity;
}
// ERC20 functions for backwards compatibility.
function allowance(address owner, address spender) public view virtual returns (uint256) {
return allowances[owner][spender];
}
function approve(address _spender, uint _value) public returns (bool) {
require(_spender != address(0), "ERC223: Spender error.");
allowances[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value) public returns (bool) {
require(allowances[_from][msg.sender] >= _value, "ERC223: Insufficient allowance.");
balances[_from] -= _value;
allowances[_from][msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}
}
contract ERC20WrapperToken is IERC20, ERC165, ERC20Rescue
{
address public creator = msg.sender;
address public wrapper_for;
mapping(address account => mapping(address spender => uint256)) private allowances;
function set(address _wrapper_for) external
{
require(msg.sender == creator);
wrapper_for = _wrapper_for;
}
uint256 private _totalSupply;
mapping(address => uint256) private balances; // List of user balances.
function balanceOf(address _owner) public view override returns (uint256) { return balances[_owner]; }
function name() public view returns (string memory) { return IERC20Metadata(wrapper_for).name(); }
function symbol() public view returns (string memory) { return string.concat(IERC223(wrapper_for).symbol(), "20"); }
function decimals() public view returns (uint8) { return IERC20Metadata(wrapper_for).decimals(); }
function totalSupply() public view override returns (uint256) { return _totalSupply; }
function origin() public view returns (address) { return wrapper_for; }
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IERC20).interfaceId ||
interfaceId == type(IERC20WrapperToken).interfaceId ||
super.supportsInterface(interfaceId);
}
function transfer(address _to, uint _value) public override returns (bool success)
{
balances[msg.sender] = balances[msg.sender] - _value;
balances[_to] = balances[_to] + _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function mint(address _recipient, uint256 _quantity) external
{
require(msg.sender == creator, "Wrapper Token: Only the creator contract can mint wrapper tokens.");
balances[_recipient] += _quantity;
_totalSupply += _quantity;
}
function burn(address _from, uint256 _quantity) external
{
require(msg.sender == creator, "Wrapper Token: Only the creator contract can destroy wrapper tokens.");
balances[_from] -= _quantity;
_totalSupply -= _quantity;
}
function allowance(address owner, address spender) public view virtual returns (uint256) {
return allowances[owner][spender];
}
function approve(address _spender, uint _value) public returns (bool) {
// Safety checks.
require(_spender != address(0), "ERC20: Spender error.");
allowances[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value) public returns (bool) {
require(allowances[_from][msg.sender] >= _value, "ERC20: Insufficient allowance.");
balances[_from] -= _value;
allowances[_from][msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}
}
contract TokenStandardConverter is IERC223Recipient
{
event ERC223WrapperCreated(address indexed _token, address indexed _ERC223Wrapper);
event ERC20WrapperCreated(address indexed _token, address indexed _ERC20Wrapper);
mapping (address => ERC223WrapperToken) public erc223Wrappers; // A list of token wrappers. First one is ERC20 origin, second one is ERC223 version.
mapping (address => ERC20WrapperToken) public erc20Wrappers;
mapping (address => address) public erc223Origins;
mapping (address => address) public erc20Origins;
mapping (address => uint256) public erc20Supply; // Token => how much was deposited.
function getERC20WrapperFor(address _token) public view returns (address)
{
return address(erc20Wrappers[_token]);
}
function getERC223WrapperFor(address _token) public view returns (address)
{
return address(erc223Wrappers[_token]);
}
function getERC20OriginFor(address _token) public view returns (address)
{
return (address(erc20Origins[_token]));
}
function getERC223OriginFor(address _token) public view returns (address)
{
return (address(erc223Origins[_token]));
}
function predictWrapperAddress(address _token,
bool _isERC20 // Is the provided _token a ERC20 or not?
// If it is set as ERC20 then we will predict the address of a
// ERC223 wrapper for that token.
// Otherwise we will predict ERC20 wrapper address.
) view external returns (address)
{
bytes memory _bytecode;
if(_isERC20)
{
_bytecode = type(ERC223WrapperToken).creationCode;
}
else
{
_bytecode = type(ERC20WrapperToken).creationCode;
}
bytes32 hash = keccak256(
abi.encodePacked(
bytes1(0xff), address(this), keccak256(abi.encode(_token)), keccak256(_bytecode)
)
);
return address(uint160(uint(hash)));
}
function tokenReceived(address _from, uint _value, bytes memory /* _data */) public override returns (bytes4)
{
require(erc223Origins[msg.sender] == address(0), "Error: creating wrapper for a wrapper token.");
// There are two possible cases:
// 1. A user deposited ERC223 origin token to convert it to ERC20 wrapper
// 2. A user deposited ERC223 wrapper token to unwrap it to ERC20 origin.
if(erc20Origins[msg.sender] != address(0))
{
// Origin for deposited token exists.
// Unwrap ERC-223 wrapper.
erc20Supply[erc20Origins[msg.sender]] -= _value;
safeTransfer(erc20Origins[msg.sender], _from, _value);
ERC223WrapperToken(msg.sender).burn(_value);
return this.tokenReceived.selector;
}
// Otherwise origin for the sender token doesn't exist
// There are two possible cases:
// 1. ERC20 wrapper for the deposited token exists
// 2. ERC20 wrapper for the deposited token doesn't exist and must be created.
else if(address(erc20Wrappers[msg.sender]) == address(0))
{
// Create ERC-20 wrapper if it doesn't exist.
createERC20Wrapper(msg.sender);
}
// Mint ERC-20 wrapper tokens for the deposited ERC-223 token
// if the ERC-20 wrapper didn't exist then it was just created in the above statement.
erc20Wrappers[msg.sender].mint(_from, _value);
return this.tokenReceived.selector;
}
function createERC223Wrapper(address _token) public returns (address)
{
require(address(erc223Wrappers[_token]) == address(0), "ERROR: Wrapper exists");
require(!isWrapper(_token), "Error: Creating wrapper for a wrapper token");
ERC223WrapperToken _newERC223Wrapper = new ERC223WrapperToken{salt: keccak256(abi.encode(_token))}();
_newERC223Wrapper.set(_token);
erc223Wrappers[_token] = _newERC223Wrapper;
erc20Origins[address(_newERC223Wrapper)] = _token;
emit ERC223WrapperCreated(_token, address(_newERC223Wrapper));
return address(_newERC223Wrapper);
}
function createERC20Wrapper(address _token) public returns (address)
{
require(address(erc20Wrappers[_token]) == address(0), "ERROR: Wrapper already exists.");
require(!isWrapper(_token), "Error: Creating wrapper for a wrapper token");
ERC20WrapperToken _newERC20Wrapper = new ERC20WrapperToken{salt: keccak256(abi.encode(_token))}();
_newERC20Wrapper.set(_token);
erc20Wrappers[_token] = _newERC20Wrapper;
erc223Origins[address(_newERC20Wrapper)] = _token;
emit ERC20WrapperCreated(_token, address(_newERC20Wrapper));
return address(_newERC20Wrapper);
}
function wrapERC20toERC223(address _ERC20token, uint256 _amount) public returns (bool)
{
// If there is no active wrapper for a token that user wants to wrap
// then create it.
if(address(erc223Wrappers[_ERC20token]) == address(0))
{
createERC223Wrapper(_ERC20token);
}
uint256 _converterBalance = IERC20(_ERC20token).balanceOf(address(this)); // Safety variable.
safeTransferFrom(_ERC20token, msg.sender, address(this), _amount);
_amount = IERC20(_ERC20token).balanceOf(address(this)) - _converterBalance;
erc20Supply[_ERC20token] += _amount;
erc223Wrappers[_ERC20token].mint(msg.sender, _amount);
return true;
}
function unwrapERC20toERC223(address _ERC20token, uint256 _amount) public returns (bool)
{
require(IERC20(_ERC20token).balanceOf(msg.sender) >= _amount, "Error: Insufficient balance.");
require(erc223Origins[_ERC20token] != address(0), "Error: provided token is not a ERC-20 wrapper.");
ERC20WrapperToken(_ERC20token).burn(msg.sender, _amount);
safeTransfer(erc223Origins[_ERC20token], msg.sender, _amount);
return true;
}
function convertERC20(address _token, uint256 _amount) public returns (bool)
{
if(isWrapper(_token)) return unwrapERC20toERC223(_token, _amount);
else return wrapERC20toERC223(_token, _amount);
}
function isWrapper(address _token) public view returns (bool)
{
return erc20Origins[_token] != address(0) || erc223Origins[_token] != address(0);
}
function extractStuckERC20(address _token) external
{
require(msg.sender == address(0x01000B5fE61411C466b70631d7fF070187179Bbf));
safeTransfer(_token, address(0x01000B5fE61411C466b70631d7fF070187179Bbf), IERC20(_token).balanceOf(address(this)) - erc20Supply[_token]);
}
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
}Security
Why converters are separated by standard
In theory, arbitrary standards could be converted to arbitrary other standards through one mechanism. However, standards may contain different internal logic, creating inconsistent conversion assumptions and security requirements. ERC7417 therefore limits its scope to ERC20 and ERC223, focusing on conversion methods suited to their respective characteristics. This avoids unexpected interactions and establishes a clear verification scope.
Accidental ERC20 deposits through transfer and rescueERC20
ERC20 permits direct deposits through transfer without the receiving contract detecting receipt.
If the recipient lacks a recovery mechanism, the assets may become inaccessible and permanently locked.
The Converter's ERC20 wrappers are subject to the same issue because they are ERC20-compatible.
The Converter therefore provides a recovery mechanism called rescueERC20 (corresponding to extractStuckERC20 in the specification) to identify and recover accidental deposits by comparing balances with legitimate conversion records.
Risks and operational considerations of relying on approve and transferFrom
The Converter uses a two-step approve → transferFrom process for ERC20 deposits.
Because these are independent transactions, confirm that approval succeeded before relying on transferFrom.
The UI and backend should verify on-chain approval confirmation and the allowance amount to avoid failures caused by race conditions or unapplied approvals.
Avoiding unlimited approvals
Many UIs encourage unlimited approvals for convenience, but excessively broad withdrawal authority can increase losses if bugs, compromised roles, or leaked keys are involved. ERC7417 does not recommend unlimited approvals. Limit approvals to the amount required and revoke or minimize them after use.
Difficulty of introspecting token standards and hybrid implementations
There is no reliable introspection mechanism that guarantees with 100% certainty which standard a contract actually conforms to.
For example, a hybrid implementation can expose ERC20 functions such as approve and transferFrom while internally invoking ERC223-style callbacks in transfer.
The Converter can also create an ERC223 wrapper for such a token.
Although this does not cause a fatal problem in the workflow itself, the existence of an ERC223 wrapper in the Converter does not establish that the original token is fully ERC20-compatible.
In practice, combine supplemental introspection such as standard() with verification procedures such as actual transfer tests.
Assumption that the token standard is not verified when creating wrappers
Because there is no reliable automated identification method, the Converter does not verify whether a provided address is genuinely ERC20 or ERC223. Consequently, both an ERC20 wrapper and an ERC223 wrapper can be created for the same original token. Each wrapper token must correspond to exactly one original token, and a wrapper cannot itself be wrapped again. Upstream and downstream contracts must account for the possibility of up to two wrapper types per original token, one for ERC20 and one for ERC223.
Incompatibility with tokens whose supply decays or is burned
The Converter assumes that balances of original tokens deposited for conversion do not decrease autonomously. If the original token's supply decays over time or its balance decreases through burns, taxes, or similar mechanisms, the Converter's holdings may become insufficient, breaking the 1:1 conversion guarantee. In such cases, a Converter-issued alternative version (wrapper) should not be provided for that token.
Summary of security considerations
| Issue | Description | Impact | Recommended practice |
|---|---|---|---|
| Standard-specific converters | Limit the scope to ERC20 and ERC223 | Reduce unexpected behavior | Separate conversion logic by target standard |
| Accidental ERC20 deposits | transfer can deposit tokens without receipt detection |
Assets may become locked | Recover the balance difference through a rescueERC20-equivalent mechanism |
| Two-step approval | approve and transferFrom are separate transactions |
Timing races | Verify approval confirmation and allowance |
| Unlimited approvals | Convenient but riskier | Increased losses | Limit amounts and revoke after use |
| Difficult standard introspection | Visible interface and actual behavior may differ | Misclassification | Combine standard() and actual transfer tests |
| No wrapper-standard verification | Two wrappers can exist for one original token | Differences in design assumptions | Do not allow a wrapper itself to be the subject of wrapping |
| Decaying supply | Token balances decrease autonomously | Loss of 1:1 backing | Exclude such tokens |
References
Dexaran (@Dexaran) dexaran@ethereumclassic.org, "ERC-7417: Token Converter [DRAFT]," Ethereum Improvement Proposals, no. 7417, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7417.
Conclusion
This article covered ERC7417, a proposal to improve compatibility and convenience through bidirectional conversion between ERC20 and ERC223 token standards on Ethereum. I hope it helped clarify the mechanism.
If you have questions, feel free to reach out via Twitter DM.
I also publish on the following platforms.



