> For the complete documentation index, see [llms.txt](https://docs.facet.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facet.org/developer-tools/facet-sol-foundry.md).

# 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 %}
