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 ERC6353, a proposal for sending a percentage of an ERC20 token transfer to a separate address.
This article translates, summarizes, and elaborates on the following specification.
I have also written about a range of other EIPs.
Overview
ERC6353 extends ERC20 tokens so that a percentage of each transfer can automatically be sent to a third party. For example, a token transfer can also trigger a donation to a designated charity. The same mechanism can be used to automate a savings program.
Motivation
Many charities already have blockchain addresses, and some token holders would like to donate automatically whenever they transfer tokens. However, the existing ERC20 standard does not define a mechanism for doing so.
Standardizing this mechanism would make it easier for both users and application developers. Users could donate with little effort, while projects could manage donations more easily. Allowing token holders to compare donation rates could also improve transparency and support a more sustainable blockchain ecosystem.
ERC6353 offers the following benefits.
- Effortless donations
- Simply transferring tokens automatically makes a donation, allowing users to contribute to social causes without extra steps.
- Ease of use through standardization
- Developers can implement the same interface across projects.
- Greater transparency
- Users can easily identify which tokens support which organizations and see where donations go.
- Other potential applications
- For example, automatically sending a percentage of each transfer to a savings account can help users save money.
Specification
Role of the contract owner
After vetting a charity, the contract owner can register its address in whitelistedRate (the allowlist).
The owner can also configure a global default donation rate.
When registering an address, the donation rate must not be unset (null).
Options for token holders
Token holders can select a donation recipient through _defaultAddress (the default recipient).
The address should not be a null (null address) value.
If the recipient is null, the donation feature is inactive.
Calculating donations
Donations are calculated as a percentage, although the exact calculation can vary.
Projects and applications that adopt this specification can use charityInfo() to retrieve the donation rate assigned to each address.
Transfer processing
This standard extends the transfer (direct transfer), transferFrom (delegated transfer), and approve (approval) functions to handle donations automatically.
-
When
transferortransferFromis called, the following happens.- The transfer amount and donation amount are deducted from the sender's balance.
- The transfer amount is credited to the recipient.
- The donation amount is sent to the designated charity.
- Two
Transferevents are emitted, one for the regular transfer and one for the donation.
-
Insufficient balance
- If the combined transfer and donation amounts exceed the sender's balance, the transaction will
revert(fail).
- If the combined transfer and donation amounts exceed the sender's balance, the transaction will
Interface
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.4;
///
/// @dev Required interface of an ERC20 Charity compliant contract.
///
interface IERC20charity is IERC165 {
/// The EIP-165 identifier for this interface is 0x557512b6
/**
* @dev Emitted when `toAdd` charity address is added to `whitelistedRate`.
*/
event AddedToWhitelist (address toAdd);
/**
* @dev Emitted when `toRemove` charity address is deleted from `whitelistedRate`.
*/
event RemovedFromWhitelist (address toRemove);
/**
* @dev Emitted when `_defaultAddress` charity address is modified and set to `whitelistedAddr`.
*/
event DonnationAddressChanged (address whitelistedAddr);
/**
* @dev Emitted when `_defaultAddress` charity address is modified and set to `whitelistedAddr`
* and _donation is set to `rate`.
*/
event DonnationAddressAndRateChanged (address whitelistedAddr,uint256 rate);
/**
* @dev Emitted when `whitelistedRate` for `whitelistedAddr` is modified and set to `rate`.
*/
event ModifiedCharityRate(address whitelistedAddr,uint256 rate);
/**
*@notice Called with the charity address to determine if the contract whitelisted the address
*and if it is the rate assigned.
*@param addr - the Charity address queried for donnation information.
*@return whitelisted - true if the contract whitelisted the address to receive donnation
*@return defaultRate - the rate defined by the contract owner by default , the minimum rate allowed different from 0
*/
function charityInfo(
address addr
) external view returns (
bool whitelisted,
uint256 defaultRate
);
/**
*@notice Add address to whitelist and set rate to the default rate.
* @dev Requirements:
*
* - `toAdd` cannot be the zero address.
*
* @param toAdd The address to whitelist.
*/
function addToWhitelist(address toAdd) external;
/**
*@notice Remove the address from the whitelist and set rate to the default rate.
* @dev Requirements:
*
* - `toRemove` cannot be the zero address.
*
* @param toRemove The address to remove from whitelist.
*/
function deleteFromWhitelist(address toRemove) external;
/**
*@notice Get all registered charity addresses.
*/
function getAllWhitelistedAddresses() external ;
/**
*@notice Display for a user the rate of the default charity address that will receive donation.
*/
function getRate() external view returns (uint256);
/**
*@notice Set personlised rate for charity address in {whitelistedRate}.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
* - `rate` cannot be inferior to the default rate.
*
* @param whitelistedAddr The address to set as default.
* @param rate The personalised rate for donation.
*/
function setSpecificRate(address whitelistedAddr , uint256 rate) external;
/**
*@notice Set for a user a default charity address that will receive donation.
* The default rate specified in {whitelistedRate} will be applied.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
*
* @param whitelistedAddr The address to set as default.
*/
function setSpecificDefaultAddress(address whitelistedAddr) external;
/**
*@notice Set for a user a default charity address that will receive donation.
* The rate is specified by the user.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
* - `rate` cannot be less than to the default rate
* or to the rate specified by the owner of this contract in {whitelistedRate}.
*
* @param whitelistedAddr The address to set as default.
* @param rate The personalised rate for donation.
*/
function setSpecificDefaultAddressAndRate(address whitelistedAddr , uint256 rate) external;
/**
*@notice Display for a user the default charity address that will receive donation.
* The default rate specified in {whitelistedRate} will be applied.
*/
function specificDefaultAddress() external view returns (
address defaultAddress
);
/**
*@notice Delete The Default Address and so deactivate donnations .
*/
function deleteDefaultAddress() external;
}IERC20charity defines an extension that adds donation functionality to ERC20 tokens. It allows a specified percentage of a token transfer to be donated automatically to a designated charity.
Events
Several events are defined to help detect changes within the contract.
- AddedToWhitelist
- Emitted when a charity address is added to the allowlist (
whitelistedRate).
- Emitted when a charity address is added to the allowlist (
- RemovedFromWhitelist
- Emitted when a charity address is removed from the allowlist.
- DonnationAddressChanged
- Emitted when the default donation recipient changes.
- DonnationAddressAndRateChanged
- Emitted when both the default recipient and donation rate change.
- ModifiedCharityRate
- Emitted when the donation rate for an allowlisted address changes.
Functions
charityInfo
Checks whether a specified address is registered as a donation recipient and, if so, retrieves its donation rate.
addToWhitelist
Adds a new charity address to the allowlist and assigns the default donation rate.
The zero address (0x0) cannot be registered.
deleteFromWhitelist
Removes a charity address from the allowlist and resets its donation rate to the default value, as described by the interface. The zero address cannot be removed.
getAllWhitelistedAddresses
Retrieves all charity addresses registered in the allowlist.
getRate
Retrieves the donation rate for the user's selected default recipient.
setSpecificRate
Sets a custom donation rate for a particular charity. The zero address cannot be used. The rate must be at least the default donation rate.
setSpecificDefaultAddress
Sets the user's default donation recipient. Only addresses registered in the allowlist can be selected.
setSpecificDefaultAddressAndRate
Sets both the user's default donation recipient and donation rate. The zero address cannot be used. The donation rate must be at least the default rate.
specificDefaultAddress
Retrieves the user's current default donation recipient.
deleteDefaultAddress
Removes the configured default recipient, disabling donations.
Additional Notes
Why use an allowlist?
ERC6353 registers charity addresses in an allowlist.
Specifically, addresses are stored in an array, and a mapping (whitelistedRate) tracks whether each address is active.
This gives users a choice of donation recipients and makes it clear which addresses are eligible to receive donations.
The contract owner could also configure a single recipient and change it periodically, allowing projects to adopt different donation strategies.
Transfer processing and how revert works
If the sender's balance is insufficient to cover both the transfer and donation, the transaction will revert (fail).
Allowing a transfer to proceed despite an insufficient balance could cause unintended behavior.
Donations are handled within the transfer function.
This simplifies the implementation because no separate donation function is needed.
An implementer might also consider an alternative design that allows the regular transfer to succeed when the donation cannot be covered.
Managing donated funds
Projects can choose how donations are handled.
- Direct donations
Send the donation portion directly to the charity when the tokens are transferred.
- Accumulate donations in the contract for later withdrawal
Keep donated tokens in the contract so that the charity can withdraw them later.
In this case, the charity could claim the tokens through a withdraw or claim function.
Rather than receiving donations directly from token holders, the charity can collect its accumulated donations when needed.
Calculating the donation amount
ERC6353 calculates donations as a percentage of the transfer amount. Even small transfers therefore result in proportional donations, making the mechanism suitable for a variety of situations.
Token implementers might also consider alternative calculation methods.
- Rounding up the transfer amount and donating the difference (for example, spending
100tokens for a transfer of99.5tokens and donating0.5tokens). - Triggering donations only when the transfer amount exceeds a specified threshold.
In addition to the standard percentage-based approach, donation calculations can be customized in alternative designs.
Compatibility
ERC6353 extends ERC20 while preserving its standard interfaces and functionality. One potential compatibility issue is that transfers may fail when the account does not have enough funds to cover the additional donation.
Reference Implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IERC20charity.sol";
/**
*@title ERC720 charity Token
*@author Aubay
*@dev Extension of ERC720 Token that can be partially donated to a charity project
*
*This extensions keeps track of donations to charity addresses. The owner can chose the charity adresses listed.
*Users can active the donation option or not and specify a different pourcentage than the default one donate.
* A pourcentage af the amount of token transfered will be added and send to a charity address.
*/
abstract contract ERC20Charity is IERC20charity, ERC20, Ownable {
mapping(address => uint256) public whitelistedRate; //Keep track of the rate for each charity address
mapping(address => uint256) internal indexOfAddresses;
mapping(address => mapping(address => uint256)) private _donation; //Keep track of the desired rate to donate for each user
mapping(address => address) private _defaultAddress; //keep track of each user's default charity address
address[] whitelistedAddresses; //Addresses whitelisted
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165) returns (bool) {
return
interfaceId == type(IERC20charity).interfaceId ||
interfaceId == type(IERC165).interfaceId;
}
/**
*@dev The default rate of donation can be override
*/
function _defaultRate() internal pure virtual returns (uint256) {
return 10; // 0.1%
}
/**
*@dev The denominator to interpret the rate of donation , defaults to 10000 so rate are expressed in basis points, but may be customized by an override.
* base 10000 , so 10000 =100% , 0 = 0% , 2000 =20%
*/
function _feeDenominator() internal pure virtual returns (uint256) {
return 10000;
}
/**
*@notice Add address to whitelist and set rate to the default rate.
* @dev Requirements:
*
* - `toAdd` cannot be the zero address.
*
* @param toAdd The address to whitelist.
*/
function addToWhitelist(address toAdd) external virtual onlyOwner {
if (indexOfAddresses[toAdd] == 0) {
whitelistedRate[toAdd] = _defaultRate();
whitelistedAddresses.push(toAdd);
indexOfAddresses[toAdd] = whitelistedAddresses.length;
}
emit AddedToWhitelist(toAdd);
}
/**
*@notice Remove the address from the whitelist and set rate to the default rate.
* @dev Requirements:
*
* - `toRemove` cannot be the zero address.
*
* @param toRemove The address to remove from whitelist.
*/
function deleteFromWhitelist(address toRemove) external virtual onlyOwner {
uint256 index1 = indexOfAddresses[toRemove];
require(index1 > 0, "Invalid index"); //Indexing starts at 1, 0 is not allowed
// move the last item into the index being vacated
address lastValue = whitelistedAddresses[
whitelistedAddresses.length - 1
];
whitelistedAddresses[index1 - 1] = lastValue; // adjust for 1-based indexing
indexOfAddresses[lastValue] = index1;
whitelistedAddresses.pop();
indexOfAddresses[toRemove] = 0;
delete whitelistedRate[toRemove]; //whitelistedRate[toRemove] =0;
emit RemovedFromWhitelist(toRemove);
}
/// @notice Get all registered charity addresses
/// @return List of all registered donations addresses
function getAllWhitelistedAddresses() external view returns (address[] memory) {
return whitelistedAddresses;
}
/// @notice Display for a user the rate of the default charity address that will receive donation.
/// @return The default rate of the registered address for the user.
function getRate() external view returns (uint256) {
return _donation[msg.sender][_defaultAddress[msg.sender]];
}
/**
*@notice Set for a user a default charity address that will receive donation.
* The default rate specified in {whitelistedRate} will be applied.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
*
* @param whitelistedAddr The address to set as default.
*/
function setSpecificDefaultAddress(
address whitelistedAddr
) external virtual {
require(
whitelistedRate[whitelistedAddr] != 0,
"ERC20Charity: invalid whitelisted rate"
);
_defaultAddress[msg.sender] = whitelistedAddr;
_donation[msg.sender][whitelistedAddr] = whitelistedRate[
whitelistedAddr
];
emit DonnationAddressChanged(whitelistedAddr);
}
/**
*@notice Set for a user a default charity address that will receive donation.
* The rate is specified by the user.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
* - `rate` cannot be inferior to the default rate
* or to the rate specified by the owner of this contract in {whitelistedRate}.
*
* @param whitelistedAddr The address to set as default.
* @param rate The personalised rate for donation.
*/
function setSpecificDefaultAddressAndRate(
address whitelistedAddr,
uint256 rate
) external virtual {
require(
rate <= _feeDenominator(),
"ERC20Charity: rate must be between 0 and _feeDenominator"
);
require(
rate >= _defaultRate(),
"ERC20Charity: rate fee must exceed default rate"
);
require(
rate >= whitelistedRate[whitelistedAddr],
"ERC20Charity: rate fee must exceed the fee set by the owner"
);
require(
whitelistedRate[whitelistedAddr] != 0,
"ERC20Charity: invalid whitelisted address"
);
_defaultAddress[msg.sender] = whitelistedAddr;
_donation[msg.sender][whitelistedAddr] = rate;
emit DonnationAddressAndRateChanged(whitelistedAddr, rate);
}
/**
*@notice Set personlised rate for charity address in {whitelistedRate}.
* @dev Requirements:
*
* - `whitelistedAddr` cannot be the zero address.
* - `rate` cannot be inferior to the default rate.
*
* @param whitelistedAddr The address to set as default.
* @param rate The personalised rate for donation.
*/
function setSpecificRate(
address whitelistedAddr,
uint256 rate
) external virtual onlyOwner {
require(
rate <= _feeDenominator(),
"ERC20Charity: rate must be between 0 and _feeDenominator"
);
require(
rate >= _defaultRate(),
"ERC20Charity: rate fee must exceed default rate"
);
require(
whitelistedRate[whitelistedAddr] != 0,
"ERC20Charity: invalid whitelisted address"
);
whitelistedRate[whitelistedAddr] = rate;
emit ModifiedCharityRate(whitelistedAddr, rate);
}
/**
*@notice Display for a user the default charity address that will receive donation.
* The default rate specified in {whitelistedRate} will be applied.
*/
function specificDefaultAddress() external view virtual returns (address) {
return _defaultAddress[msg.sender];
}
/**
* inherit IERC20charity
*/
function charityInfo(
address charityAddr
) external view virtual returns (bool, uint256 rate) {
rate = whitelistedRate[charityAddr];
if (rate != 0) {
return (true, rate);
} else {
return (false, rate);
}
}
/**
*@notice Delete The Default Address and so deactivate donnations .
*/
function deleteDefaultAddress() external virtual {
_defaultAddress[msg.sender] = address(0);
emit DonnationAddressChanged(address(0));
}
/**
*@notice Return the rate to donate.
* @dev Requirements:
*
* - `from` cannot be the zero address
*
* @param from The address to get rate of donation.
*/
function _returnRate(address from) internal virtual returns (uint256 rate) {
address whitelistedAddr = _defaultAddress[from];
rate = _donation[from][whitelistedAddr];
if (
whitelistedRate[whitelistedAddr] == 0 ||
_defaultAddress[from] == address(0)
) {
rate = 0;
}
return rate;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(
address to,
uint256 amount
) public virtual override returns (bool) {
address owner = _msgSender();
if (_defaultAddress[msg.sender] != address(0)) {
address whitelistedAddr = _defaultAddress[msg.sender];
uint256 rate = _returnRate(msg.sender);
uint256 donate = (amount * rate) / _feeDenominator();
_transfer(owner, whitelistedAddr, donate);
}
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
if (_defaultAddress[from] != address(0)) {
address whitelistedAddr = _defaultAddress[from];
uint256 rate = _returnRate(from);
uint256 donate = (amount * rate) / _feeDenominator();
_spendAllowance(from, spender, donate);
_transfer(from, whitelistedAddr, donate);
}
_transfer(from, to, amount);
return true;
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(
address spender,
uint256 amount
) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
if (_defaultAddress[msg.sender] != address(0)) {
uint256 rate = _returnRate(msg.sender);
uint256 donate = (amount * rate) / _feeDenominator();
_approve(owner, spender, (donate + amount));
}
return true;
}
}Citation
Aubay blockchain-team@aubay.com, BOCA Jeabby (@bjeabby1507), EL MERSHATI Laith (@lth-elm), KEMP Elia (@eliakemp), "ERC-6353: Charity token [DRAFT]," Ethereum Improvement Proposals, no. 6353, May 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6353.
Conclusion
This article covered ERC6353, a proposal for sending a percentage of an ERC20 token transfer to a separate address.
If you have any questions, feel free to reach out via a direct message on Twitter.
I also publish content on other platforms.



