1/5
_Follow along with this video:_ --- ```js #define constant NUMBER_OF_HORSES_STORAGE_SLOT = FREE_STORAGE_POINTER() ``` Now, we're going to need to reference this storage slot in our `SET_NUMBER_OF_HORSES()` macro. The syntax for this is something new! > **Note:** We're doing things a little out of order here, but we'll assure our operations are executed in the correct order by the end. ```js #define macro SET_NUMBER_OF_HORSES() = takes(0) returns(0){ // 1. Get the value to store from call data // 2. Give numberOfHorses a storage slot [NUMBER_OF_HORSES_STORAGE_SLOT] // [0] // 3. Execute the SSTORE op code } ``` The syntax above references our defined constant and pushes its value to the top of our stack. `NUMBER_OF_HORSES_STORAGE_SLOT` is assigned a value of 0, thus 0 is added to the top of our stack. With our storage slot constant defined, we're now going to need the value we're storing. In the next lesson, we'll dive into how to isolate the function parameters from the `call data` passed to our contract. See you there!
A comprehensive guide to accessing constant variables in Huff - This lesson covers how to define constant variables, assign them values and reference their values in your code using the `FREE_STORAGE_POINTER` keyword, and how to store a value into the storage slot that the constant variable represents.
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:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Solidity Developer
Assembly and Formal VerificationDuration: 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:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar