i have a contract who containt a function onTokenTransfer(address _sender, uint256 _fee, bytes memory _data)
, when i transfer some ERC-20 Token using ERC-677 function transferAndCall
, the function onTokenTransfer
in my contract trigger logic in it and call another function in my contract and for this i found two alternatives :
FIRST ONE :
i use low-level call :
function onTokenTransfer(
address _sender,
uint256 _fee,
bytes memory _data
) public {
require(_fee >= fee, "NOT ENOUGH FUNDS");
(bool success, ) = address(this).call(_data);
require(success, "NOT SUCCESS");
}
but I saw that I have to use it as little as possible for different reasons .
SECOND ONE :
decode data and then call my function :
function onTokenTransfer(
address _sender,
uint256 _fee,
bytes memory _data
) public {
require(_fee >= fee, "NOT ENOUGH FUNDS");
myFunction(parameter); // for this i have to decode data to get the parameter value
require(success, "NOT SUCCESS");
}
What is the best solution between those two, and if its the second one how to decode data to get the parameter value ? Thank you