{"id":13759355,"url":"https://github.com/huff-language/foundry-huff","last_synced_at":"2025-05-10T09:32:24.993Z","repository":{"id":37244021,"uuid":"503776948","full_name":"huff-language/foundry-huff","owner":"huff-language","description":"A Foundry Library for compiling, debugging, and working with Huff contracts in Solidity.","archived":false,"fork":false,"pushed_at":"2024-07-03T16:13:11.000Z","size":323,"stargazers_count":260,"open_issues_count":27,"forks_count":51,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-16T16:37:05.712Z","etag":null,"topics":["bytecode","evm","foundry","huff","huff-lang","solidity"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huff-language.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-15T13:27:25.000Z","updated_at":"2024-11-14T15:15:30.000Z","dependencies_parsed_at":"2024-08-03T13:13:23.419Z","dependency_job_id":null,"html_url":"https://github.com/huff-language/foundry-huff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huff-language%2Ffoundry-huff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huff-language%2Ffoundry-huff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huff-language%2Ffoundry-huff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huff-language%2Ffoundry-huff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huff-language","download_url":"https://codeload.github.com/huff-language/foundry-huff/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253397056,"owners_count":21901985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","evm","foundry","huff","huff-lang","solidity"],"created_at":"2024-08-03T13:00:51.445Z","updated_at":"2025-05-10T09:32:24.543Z","avatar_url":"https://github.com/huff-language.png","language":"Solidity","readme":"\u003cimg align=\"right\" width=\"400\" height=\"160\" top=\"140\" src=\"./assets/foundry_huff_banner.jpg\"\u003e\n\n\n# Foundry x Huff\n\n[![ci](https://github.com/huff-language/huff-rs/actions/workflows/ci.yaml/badge.svg)](https://github.com/huff-language/huff-rs/actions/workflows/ci.yaml) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![Discord](https://img.shields.io/discord/980519274600882306)\n\nA [foundry](https://github.com/foundry-rs/foundry) library for working with [huff](https://github.com/huff-language/huff-rs) contracts. Take a look at our [project template](https://github.com/huff-language/huff-project-template) to see an example project that uses this library.\n\n\n## Installing\n\nFirst, install the [huff compiler](https://github.com/huff-language/huff-rs) by running:\n```\ncurl -L get.huff.sh | bash\n```\n\nThen, install this library with [forge](https://github.com/foundry-rs/foundry):\n```\nforge install huff-language/foundry-huff\n```\n\n\n## Usage\n\nThe HuffDeployer is a Solidity library that takes a filename and deploys the corresponding Huff contract, returning the address that the bytecode was deployed to. To use it, simply import it into your file by doing:\n\n```js\nimport {HuffDeployer} from \"foundry-huff/HuffDeployer.sol\";\n```\n\nTo compile contracts, you can use `HuffDeployer.deploy(string fileName)`, which takes in a single string representing the filename's path relative to the `src` directory. Note that the file ending, i.e. `.huff`, must be omitted.\nHere is an example deployment (where the contract is located in [`src/test/contracts/Number.huff`](./src/test/contracts/Number.huff)):\n\n```solidity\n// SPDX-License-Identifier: Apache-2.0\npragma solidity \u003e=0.7.0 \u003c0.9.0;\n\nimport {HuffDeployer} from \"foundry-huff/HuffDeployer\";\n\ninterface Number {\n  function setNumber(uint256) external;\n  function getNumber() external returns (uint256);\n}\n\ncontract HuffDeployerExample {\n  function deploy() public {\n    // Deploy a new instance of src/test/contracts/Number.huff\n    address addr = HuffDeployer.deploy(\"test/contracts/Number\");\n\n    // To call a function on the deployed contract, create an interface and wrap the address like so\n    Number number = Number(addr);\n  }\n}\n```\n\nTo deploy a Huff contract with constructor arguments, you can _chain_ commands onto the HuffDeployer.\n\nFor example, to deploy the contract [`src/test/contracts/Constructor.huff`](src/test/contracts/Constructor.huff) with arguments `(uint256(0x420), uint256(0x420))`, you are encouraged to follow the logic defined in the `deploy` function of the `HuffDeployerArguments` contract below.\n\n```solidity\n// SPDX-License-Identifier: Apache-2.0\npragma solidity \u003e=0.7.0 \u003c0.9.0;\n\nimport {HuffDeployer} from \"foundry-huff/HuffDeployer\";\n\ninterface Constructor {\n  function getArgOne() external returns (address);\n  function getArgTwo() external returns (uint256);\n}\n\ncontract HuffDeployerArguments {\n  function deploy() public {\n    // Deploy the contract with arguments\n    address addr = HuffDeployer\n      .config()\n      .with_args(bytes.concat(abi.encode(uint256(0x420)), abi.encode(uint256(0x420))))\n      .deploy(\"test/contracts/Constructor\");\n\n    // To call a function on the deployed contract, create an interface and wrap the address\n    Constructor construct = Constructor(addr);\n\n    // Validate we deployed the Constructor with the correct arguments\n    assert(construct.getArgOne() == address(0x420));\n    assert(construct.getArgTwo() == uint256(0x420));\n  }\n\n  function depreciated_deploy() public {\n    address addr = HuffDeployer.deploy_with_args(\n      \"test/contracts/Constructor\",\n      bytes.concat(abi.encode(uint256(0x420)), abi.encode(uint256(0x420)))\n    );\n\n    // ...\n  }\n}\n```\n\nHuffDeployer also enables you to instantiate contracts, from the test file, even if they have _no constructor macro_!\n\nThis is possible by using [Foundry](https://github.com/foundry-rs/foundry)'s [ffi](https://book.getfoundry.sh/cheatcodes/ffi.html) cheatcode.\n\n_NOTE: It is highly recommended that you read the foundry book, or at least familiarize yourself with foundry, before using this library to avoid easily susceptible footguns._\n\nLet's use the huff contract [`src/test/contracts/NoConstructor.huff`](./src/test/contracts/NoConstructor.huff), which has no defined constructor macro. The inline-instantiation defined in the `deploy` function of the `HuffDeployerCode` contract below is recommended.\n\n```solidity\n// SPDX-License-Identifier: Apache-2.0\npragma solidity \u003e=0.7.0 \u003c0.9.0;\n\nimport {HuffDeployer} from \"foundry-huff/HuffDeployer\";\n\ninterface Constructor {\n  function getArgOne() external returns (address);\n  function getArgTwo() external returns (uint256);\n}\n\ncontract HuffDeployerCode {\n\n  function deploy() public {\n    // Define a new constructor macro as a string\n    string memory constructor_macro = \"#define macro CONSTRUCTOR() = takes(0) returns (0) {\"\n      \"    // Copy the first argument into memory \\n\"\n      \"    0x20                        // [size] - byte size to copy \\n\"\n      \"    0x40 codesize sub           // [offset, size] - offset in the code to copy from\\n \"\n      \"    0x00                        // [mem, offset, size] - offset in memory to copy to \\n\"\n      \"    codecopy                    // [] \\n\"\n      \"    // Store the first argument in storage\\n\"\n      \"    0x00 mload                  // [arg] \\n\"\n      \"    [CONSTRUCTOR_ARG_ONE]       // [CONSTRUCTOR_ARG_ONE, arg] \\n\"\n      \"    sstore                      // [] \\n\"\n      \"    // Copy the second argument into memory \\n\"\n      \"    0x20                        // [size] - byte size to copy \\n\"\n      \"    0x20 codesize sub           // [offset, size] - offset in the code to copy from \\n\"\n      \"    0x00                        // [mem, offset, size] - offset in memory to copy to \\n\"\n      \"    codecopy                    // [] \\n\"\n      \"    // Store the second argument in storage \\n\"\n      \"    0x00 mload                  // [arg] \\n\"\n      \"    [CONSTRUCTOR_ARG_TWO]       // [CONSTRUCTOR_ARG_TWO, arg] \\n\"\n      \"    sstore                      // [] \\n\"\n      \"}\";\n\n    // Deploy the contract with arguments\n    address addr = HuffDeployer\n      .config()\n      .with_args(bytes.concat(abi.encode(uint256(0x420)), abi.encode(uint256(0x420))))\n      .with_code(constructor_macro)\n      .deploy(\"test/contracts/NoConstructor\");\n\n    // To call a function on the deployed contract, create an interface and wrap the address\n    Constructor construct = Constructor(addr);\n\n    // Validate we deployed the Constructor with the correct arguments\n    assert(construct.getArgOne() == address(0x420));\n    assert(construct.getArgTwo() == uint256(0x420));\n  }\n\n  function depreciated_deploy_with_code() public {\n    address addr = HuffDeployer.deploy_with_code(\n      \"test/contracts/Constructor\",\n      constructor_macro\n    );\n\n    // ...\n  }\n}\n```\n","funding_links":[],"categories":["dApps directory","Official huff-language Github repo"],"sub_categories":["Dapp Templates"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuff-language%2Ffoundry-huff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuff-language%2Ffoundry-huff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuff-language%2Ffoundry-huff/lists"}