2

for the given receive function , is there a way I can detect the receiving tokens address (Detect what coin my contract is receiving )

is it possible to extract this information from msg ?

receive() payable external {
    balance += msg.value;
    emit TransferReceived(msg.sender, msg.value);
}    

1 Answer 1

3

The receive function is triggered by a transfer of the native token only, such as ETH on Ethereum or BNB on Binance Smart Chain.

Therefore, msg.value is always an amount of the native token and never an amount of any ERC-20 token.

1
  • Thank you for clarifying that
    – 0xD1x0n
    Jan 23 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.