why do we need receive() function at all, why not use fallback() everywhere? #35
-
From the flowchart shown at https://youtu.be/gyMwXuJrbJQ?t=19457. This clearly indicates that if we do not write receive() function and use only the fallback() function, all calls will be routed through the fallback() function. This brings me to the question, why do we need receive() function at all, why not use fallback() everywhere? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello @SrikanthAlva |
Beta Was this translation helpful? Give feedback.
-
Long story short: You may want your contract to act differently when you are sent ether vs sent data. You could 100% always use the fallback, but it'll be a little more gas efficient if you do have different functionality to have both. Otherwise, you'd have to do some data validation in your fallback to check for data. |
Beta Was this translation helpful? Give feedback.
Long story short:
You may want your contract to act differently when you are sent ether vs sent data. You could 100% always use the fallback, but it'll be a little more gas efficient if you do have different functionality to have both. Otherwise, you'd have to do some data validation in your fallback to check for data.