# Facet Sol Foundry

`facet-sol` enables you to create Facet transactions in a Foundry environment:

{% embed url="<https://github.com/0xFacet/facet-sol>" %}

Install with `forge install 0xFacet/facet-sol`.

To send Facet transactions from a smart contract, first import `LibFacet`:

<pre class="language-solidity"><code class="lang-solidity"><strong>import { LibFacet } from "lib/facet-sol/src/utils/LibFacet.sol";
</strong></code></pre>

Now you can send transactions like this:

```solidity
LibFacet.sendFacetTransaction({
    value: 0,
    gasLimit: 500_000,
    data: type(SimpleStorage).creationCode
});
```

However you can't use LibFacet directly to send transactions from within a Foundry script. This is because Foundry scripts are run as EOAs and EOAs send Facet transactions using L1 transactions, not events.

facet-sol has a separate library for creating Facet transactions from within foundry scripts, FacetScript. Here's an example:

```solidity
// script/Deploy.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { FacetScript } from "lib/facet-sol/src/foundry-utils/FacetScript.sol";
import { Example } from "lib/facet-sol/src/Example.sol";
import {Script, console} from "forge-std/Script.sol";

contract DeployExample is FacetScript {
    function setUp() public override {
        super.setUp();
    }

    function run() public broadcast {
        address deployAddress = nextL2Address();
        console.log("Contract will be deployed at:", deployAddress);
        
        sendFacetTransactionFoundry({
            gasLimit: 5_000_000,
            data: abi.encodePacked(
                type(Example).creationCode,
                abi.encode(123, "hello!")
            )
        });
        
        bytes memory setNumberCalldata = abi.encodeWithSelector(
            Example.setNumber.selector,
            123
        );
        
        sendFacetTransactionFoundry({
            to: deployAddress,
            gasLimit: 5_000_000,
            data: setNumberCalldata
        });
    }
}

```

To run this you would use a command like:

{% code overflow="wrap" %}

```sh
L2_RPC="https://sepolia.facet.org" forge script 'script/DeployExample.s.sol' --rpc-url "https://...l1 rpc..." --private-key 0x1234 --broadcast
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.facet.org/developer-tools/facet-sol-foundry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
