I want to implement dispatcher in a smart contract. I research about this and understand theoretically but I am not getting practically. Exactly why the dispatcher is to be used? The basic thing I got that we need an apply action handler which checks code and receiver. But I want to know the exact need and some useful links for simple understanding if possible. Also any tutorials. How to implement dispatcher in smart contract? Thank you.
Usually, you don't need to implement dispatcher by yourself.
[[eosio::on_notify]] will generate a proper action dispatcher automatically. There were some security accidents by writing incomplete action dispatcher. If you don't know what you are doing exactly, it's better to rely on automatic generation of action dispatcher by
Basically, EOSIO calls
apply() function by default for every action. You can consider it like
main() in normal program. It is an entry point of executing an action.
apply() function instantiates your contract class (You should've written classes inheriting from
eosio::contract), and deserializes
data fields in action.
name indicates the name which this action wants to call like
data are arguments like
(from, to, quantity, memo) needed to be passed to function. By these information,
apply() will call a proper function and pass arguments to it.
Refer to this to understand how generated
apply() looks like.