Skip to content

solidity-evm-knowledgebase/huff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

huff

Install Huff

curl -L get.huff.sh | bash

Then

huffup

Check that it was installed correctly:

huffc --version

Compile a Contract with Huffc

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

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

Function Selector

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)

Storage

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()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published