Skip to content
ExperimentalTestnet: compiles and runs (CLI)Mainnet: Not availableSoftware: Huff Neo hnc 1.7.1Updated

Huff

Compiler Huff Neo hnc 1.7.1 (rev 2fe1d0c9); Windows zip SHA-256 d5ae8002…de6f4, exe 21c50d09…5464
EVM target -e cancun (the default osaka is newer than the chain)
ABI From #define function / #define event declarations
Status 🧪 CLI compile, deploy and call tested on chain 77240. Wallet Studio Huff support exists only on an unreleased branch.

Install

Download Huff Neo 1.7.1 from its GitHub releases (cakevm/huff-neo), verify the SHA-256 above, and put hnc on your PATH.

Example

Counter.huff
/* Starter counter (Huff, compiled by Huff Neo hnc 1.7.1). Unaudited example. */
#define function increment() nonpayable returns ()
#define function get() view returns (uint256)
#define event Incremented(uint256 value)

#define constant COUNT_SLOT = FREE_STORAGE_POINTER()

#define macro INCREMENT() = takes (0) returns (0) {
    [COUNT_SLOT] sload 0x01 add      // [v]
    dup1 [COUNT_SLOT] sstore          // [v]
    0x00 mstore                       // []
    __EVENT_HASH(Incremented) 0x20 0x00 log1
    stop
}

#define macro GET() = takes (0) returns (0) {
    [COUNT_SLOT] sload 0x00 mstore
    0x20 0x00 return
}

#define macro MAIN() = takes (0) returns (0) {
    callvalue iszero novalue jumpi
    0x00 0x00 revert
    novalue:
    0x00 calldataload 0xE0 shr
    dup1 __FUNC_SIG(increment) eq inc jumpi
    dup1 __FUNC_SIG(get) eq get jumpi
    0x00 0x00 revert
    inc: INCREMENT()
    get: GET()
}

Compile and deploy

hnc Counter.huff -b -e cancun | tail -n 1 > Counter.bin     # creation bytecode
hnc Counter.huff -r -e cancun | tail -n 1                     # runtime bytecode (for verification)
TX=$(cast send --async --keystore "$KEYSTORE" --password-file "$PASSWORD_FILE" --rpc-url "$RPC" --create "0x$(cat Counter.bin)")
cast receipt "$TX" contractAddress --rpc-url "$RPC"

Measured: 98 runtime bytes, 74,312 deployment gas, 44,252 gas for increment().

Caveats

  • Huff gives you the stack and nothing else: no type checks, no overflow checks, no ABI decoding.
  • Every macro must leave the stack balanced; one wrong jump label can make funds unreachable.
  • Treat Huff contracts as requiring expert review and extensive tests (Foundry can test Huff bytecode).

Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec