Facet Docs
  • 1. Introduction
    • Overview of Facet Protocol
    • What is Layer 1+?
    • The Based Sovereign Rollup
  • 2. Getting Started
    • Connecting a Wallet
    • Sending Transactions
    • Bridging In (and Out)
    • What about Gas?
    • Facet Apps
  • 3. Technical Details
    • Introduction
    • Facet RPC & Explorer
    • Genesis Contracts
    • Facet Transactions
      • From Calldata
      • From Event Logs
    • Facet Typescript SDK
    • Facet Sol (Foundry)
    • Chain State Derivation
    • Running a Facet Node
    • Bridging Assets
    • Building an Optimistic Bridge on Facet
    • Basic Transaction Flow
    • Facet's Gas Mechanism
      • FCT Issuance Calculation
      • FCT Gas Fee Calculation
    • Security Audits
  • 4. Community & Support
    • FAQs
    • Comparison with Other Rollups
    • Micro-Grants
    • Community Resources
    • Brand Kit
Powered by GitBook
On this page
  1. 3. Technical Details

Facet Sol (Foundry)

PreviousFacet Typescript SDKNextChain State Derivation

Last updated 2 months ago

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

Install with forge install 0xFacet/facet-sol.

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

import { LibFacet } from "lib/facet-sol/src/utils/LibFacet.sol";

Now you can send transactions like this:

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:

// 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:

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