curl -L get.huff.sh | bash
Then
huffup
Check that it was installed correctly:
huffc --version
huffc {PATH_TO_HUFF_CONTRACT}
adding -b will return the bytecode of the contract
huffc {PATH_TO_HUFF_CONTRACT} -b
To get only the runtime contract code:
huffc {PATH_TO_HUFF_CONTRACT} --bin-runtime
Example output for simplest contract: 60008060093d393df3
Macro are "functions" in Huff. Example:
#define macro MAIN() = takes(0) returns(0) {}
takes(0) means it's taking nothing from the stack returns(0) means it's returning nothing to the stack
We can define our functions at the top of the contract, and Huff will take care of converting it to the function selector. Example:
/* Interfaces */
#define function updateHorseNumber(uint256) nonpayable returns()
#define function readNumberOfHorses() view returns(uint256)
We can then use them like this:
__FUNC_SIG(updateHorseNumber)
Huff abstracts keeping track of storage variables through the FREE_STORAGE_POINTER() keyword.
#define constant STORAGE_SLOT0 = FREE_STORAGE_POINTER()
#define constant STORAGE_SLOT1 = FREE_STORAGE_POINTER()
#define constant STORAGE_SLOT2 = FREE_STORAGE_POINTER()