I am trying to create my own ERC223 token. There is not much information online on how to use new functions in ERC223 or I just don't understand it. Github of ERC223 says to implement the IERC223Recipient contract to handle cases when tokens are sent to a contract.
function transfer(address _to, uint _value, bytes calldata _data) external override returns (bool)
{
require(_value > 0);
if(isContract(_to))
{
IERC223Recipient receiver = IERC223Recipient(_to);
receiver.tokenReceived(msg.sender, _value, _data);
}
balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value);
balances[_to] = SafeMath.add(balances[_to], _value);
emit Transfer(msg.sender, _to, _value);
emit TransferData(_data);
return true;
}
I am not quite sure what _data is in this case. I watched some videos online and they say that this is bytes of a function. I don't understand which function and where to get it.
Once tokenReceived is called this happens:
struct ERC223TransferInfo
{
address token_contract;
address sender;
uint256 value;
bytes data;
}
ERC223TransferInfo private tkn;
/**
* @dev Standard ERC223 function that will handle incoming token transfers.
*
* @param _from Token sender address.
* @param _value Amount of tokens.
* @param _data Transaction metadata.
*/
function tokenReceived(address _from, uint _value, bytes memory _data) public virtual
{
/**
* @dev Note that inside of the token transaction handler the actual sender of token transfer is accessible via the tkn.sender variable
* (analogue of msg.sender for Ether transfers)
*
* tkn.value - is the amount of transferred tokens
* tkn.data - is the "metadata" of token transfer
* tkn.token_contract is most likely equal to msg.sender because the token contract typically invokes this function
*/
tkn.token_contract = msg.sender;
tkn.sender = _from;
tkn.value = _value;
tkn.data = _data;
// ACTUAL CODE
}
where tnk is struct above. The developer provides the code and leaves the // ACTUAL CODE comment that confuses me a lot.
I hope it is not a dumb question. I am very stuck on how to use the new ERC223 functions
Thank you!