I am currently developing a donation smart contract for the Polygon blockchain. The donation contract should receive many types of coins like (MATIC, USDT, USDC, etc.).
I first made the donate function like the below:
function donate(address donor, address token, bool isNativeCoin, uint256 amount);
But later, I noticed that the Polygon network has MATIC address differently from other evm-based chains.
So I removed the isNativeCoin
flag variable in the method params.
function donate(address donor, address token, uint256 amount);
But I don't know that is real MATIC address is and how Polygon is different from other chains.
Here is my research about Polygon MATIC and WMATIC address.
MATIC
https://mumbai.polygonscan.com/address/0x0000000000000000000000000000000000001010 https://polygonscan.com/address/0x0000000000000000000000000000000000001010
WMATIC
https://mumbai.polygonscan.com/address/0x9c3c9283d3e44854697cd22d3faa240cfb032889#code https://polygonscan.com/address/0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270
If I import 0x0000000000000000000000000000000000001010 as a token in my metamask wallet, it shows the same balance with Native MATIC balance. It's so interesting.
Here is the full mockup code.
address MATIC_TOKEN = 0x0000000000000000000000000000000000001010;
DonationInfo[] donations;
function _safeTransferMatic(address to, uint256 amount) internal {
(bool success, ) = to.call{value: amount}("");
require(success, "MATIC_TRANSFER_FAILED");
}
function donate(address donor, address token, uint256 amount) {
donations.push(DonationInfo(donor, token, amount);
}
function sendDonation(uint256 donateIndex) {
if (donations[donateIndex].token == MATIC_TOKEN) {
_safeTransferMatic(charityPartner, donations[donateIndex].amount);
} else {
IERC20(donations[donateIndex].token).safeTransfer(charityPartner,donations[donateIndex].amount);
}
}
Is the above code correct or should I use isNativeCoin
flag variable?
Could you explain the Polygon MATIC address?