Copy import { LibFacet } from "lib/facet-sol/src/utils/LibFacet.sol" ;
Copy LibFacet. sendFacetTransaction ({
value : 0 ,
maxFeePerGas : 1000 gwei ,
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:
Copy // 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
});
}
}
Copy L2_RPC="https://sepolia.facet.org" forge script 'script/DeployExample.s.sol' --rpc-url "https://...l1 rpc..." --private-key 0x1234 --broadcast