huff-examples
huff-examples copied to clipboard
A collection of commonly used, vigorously tested Huff contracts for learning purposes.
huff-examples •
A Collection of Verbosely Document Huff Contracts.
Usage
Make sure you've installed the Huff Compiler as outlined in the Huff Docs.
TL;DR: curl -L get.huff.sh | bash && huffup
To verify your installation, run huffc --help
. This should print a list of available commands for the huff compiler cli.
Steps
This is how to create the contract bytecode to output Hello, World! in Huff.
-
Create a file called
hello-world.huff
and enter the following content:#define macro MAIN() = takes (0) returns (0) { 0x48656c6c6f2c20776f726c6421 0x00 mstore // Store "Hello, World!" in memory. 0x1a 0x00 return // Return 26 bytes starting from memory pointer 0. }
-
Use
huffc
to compile the contract and output bytecode:huffc hello-world.huff --bytecode
This will output something like:
6100168061000d6000396000f36c48656c6c6f2c20776f726c6421600052601a6000f3
More help
Run huffc --help
to view a full list of arguments.