5/5
_Follow along with this video:_ --- In a way, sending our `calldata` to the blockchain is like executing a Python or JavaScript script. We need to begin with an `entry point` in order for our `calldata` to be processed. In Huff, this entry point is called `MAIN`. Essentially, `MAIN` in the binary becomes the recipient of your call data and orchestrates its execution. We'll go into this in more detail later. Now, if you feel a bit overwhelmed by the barrage of terminology, hang in there with me. I promise it'll all start making a lot more sense as we delve deeper. Let's look at how function dispatching is coded in Huff. While Huff _does_ have functions, we'll largely be ignoring them in favour of `macros` which function similarly with a few nuances we'll detail later. Our `MAIN` macro in Huff is going to look like this: ``` #define macro MAIN() = takes(0) returns(0) {} ``` Above, we see how a macro is defined in Huff. The skeleton of our `MAIN` macro is outlined with the `takes` and `returns` syntax specifying the stack operations it will perform—but let's not get ahead of ourselves. To validate our setup, we can compile our Huff code. By running `huffc` on our source file: ```bash huffc src/horsestore/v1/horsestore.huff ``` If all goes well, you should see `Compiling...` with no output. This is good news! Curious to see the bytecode? Run the command with a `-b` flag: ```bash huffc -b src/horsestore/v1/horsestore.huff ``` You should receive an output that looks like this: ```bash 60008060093d393df3 ``` This bytecode is comprised of `Op Codes` which, as we mentioned previously, are the instructions we are telling the EVM to execute.
Follow along with this video:
In a way, sending our calldata
to the blockchain is like executing a Python or JavaScript script. We need to begin with an entry point
in order for our calldata
to be processed.
In Huff, this entry point is called MAIN
. Essentially, MAIN
in the binary becomes the recipient of your call data and orchestrates its execution. We'll go into this in more detail later.
Now, if you feel a bit overwhelmed by the barrage of terminology, hang in there with me. I promise it'll all start making a lot more sense as we delve deeper.
Let's look at how function dispatching is coded in Huff. While Huff does have functions, we'll largely be ignoring them in favour of macros
which function similarly with a few nuances we'll detail later.
Our MAIN
macro in Huff is going to look like this:
Above, we see how a macro is defined in Huff. The skeleton of our MAIN
macro is outlined with the takes
and returns
syntax specifying the stack operations it will perform—but let's not get ahead of ourselves.
To validate our setup, we can compile our Huff code. By running huffc
on our source file:
If all goes well, you should see Compiling...
with no output. This is good news!
Curious to see the bytecode? Run the command with a -b
flag:
You should receive an output that looks like this:
This bytecode is comprised of Op Codes
which, as we mentioned previously, are the instructions we are telling the EVM to execute.
A basic guide to defining a main function and entry point in Huff - This lesson covers what a main function does in Huff, defining a macro main and testing compilation with the huff command.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on June 6, 2025
Duration: 30min
Duration: 4h 38min
Duration: 3h 57min
Duration: 1h 56min
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on June 6, 2025