is it possible to call function in contract when it receives some erc20 token like when it receives eth ?

receive() external payable { do someting on eth receive }

receiveErc20() external payable { do something on erc20 token receive }


and more specifically can this be exploited with reentrancy like the eth ones?

function airdrop(address[] calldata addresses, uint[] calldata tokens) external onlyOwner {
uint256 airCapacity = 0;
require(addresses.length == tokens.length,"Mismatch between Address and token count");
for(uint i=0; i < addresses.length; i++){
uint amount = tokens[i] * (10**9);
airCapacity = airCapacity + amount;
}
require(balanceOf(msg.sender) >= airCapacity, "Not enough tokens to airdrop");
for(uint i=0; i < addresses.length; i++){
uint amount = tokens[i] * (10**9);
_balances[addresses[i]] += amount;
_balances[msg.sender] -= amount;
emit Transfer(msg.sender, addresses[i], amount);
}
}

Mar 10, 2023, 12:00 PM
Do i understand this correctly? Actually there is transfer going on because this alter users balances:
_balances[addresses[i]] += amount;
_balances[msg.sender] -= amount;

but the fraudulent contract will never know that because it cant detect this as transfer right?
i understand now, thank you very much for cooperation 🙏
Mar 10, 2023, 12:46 PM

© 2024 Draquery.com All rights reserved.