Observed since 20 Oct, 23:08 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A toolkit for Facet blockchain integration.
The @0xfacet/sdk is a TypeScript SDK designed for interacting with the Facet network, a decentralized rollup on Ethereum. This SDK simplifies sending transactions, reading from contracts, and handling Facet's unique transaction model, with full compatibility with viem and wagmi.
Install the package via npm or yarn:
npm install @0xfacet/sdk
yarn add @0xfacet/sdk
Import and use the SDK functions as needed:
// For viem users
import {
sendFacetTransaction,
writeFacetContract,
bridgeAndCall,
facetMainnet,
} from "@0xfacet/sdk/viem";
import { createWalletClient, http } from "viem";
// For wagmi users
import {
useSendFacetTransaction,
useWriteFacetContract,
useBridgeAndCall,
} from "@0xfacet/sdk/wagmi";
// For utility functions
import {
getFctMintRate,
decodeFacetEncodedTransaction,
computeFacetTransactionHash,
sendRawFacetTransaction,
} from "@0xfacet/sdk/utils";
sendFacetTransactionSends a transaction through the Facet protocol.
function sendFacetTransaction<chain, account, request, chainOverride>(
client: Client<Transport, chain, account>,
parameters: SendTransactionParameters<
chain,
account,
chainOverride,
request
> & {
mineBoost?: Hex; // Optional boost to increase FCT mining amount
}
): Promise<SendTransactionReturnType>;
writeFacetContractExecutes a write operation on a contract through the Facet infrastructure.
function writeFacetContract<
chain,
account,
abi,
functionName,
args,
chainOverride,
>(
client: Client<Transport, chain, account>,
parameters: WriteContractParameters<
abi,
functionName,
args,
chain,
account,
chainOverride
> & {
mineBoost?: Hex; // Optional boost to increase FCT mining amount
}
): Promise<WriteContractReturnType>;
bridgeAndCallBridges ETH from L1 to L2 and executes a contract call in a single transaction.
function bridgeAndCall<chain, account, abi, functionName, args, chainOverride>(
client: Client<Transport, chain, account>,
parameters: WriteContractParameters<
abi,
functionName,
args,
chain,
account,
chainOverride
>,
ethValue: bigint,
bridgeAndCallConfig?: BridgeAndCallConfig
): Promise<WriteContractReturnType>;
useSendFacetTransactionReact hook for sending Facet transactions.
function useSendFacetTransaction<config, context>(
parameters?: UseSendFacetTransactionParameters<config, context>
): UseSendFacetTransactionReturnType<config, context>;
The transaction parameters can include the optional mineBoost property to increase the amount of FCT mined by the transaction.
useWriteFacetContractReact hook for executing write operations on contracts through Facet.
function useWriteFacetContract<abi, functionName, args, config, context>(
parameters?: UseWriteFacetContractParameters<
abi,
functionName,
args,
config,
context
>
): UseWriteFacetContractReturnType<abi, functionName, args, config, context>;
The contract write parameters can include the optional mineBoost property to increase the amount of FCT mined by the transaction.
useBridgeAndCallReact hook for bridging ETH from L1 to L2 and executing a call on L2.
function useBridgeAndCall<config, context>(
parameters?: UseBridgeAndCallParameters<config, context>
): UseBridgeAndCallReturnType<config, context>;
getFctMintRateRetrieves the current FCT mint rate from the L1 block contract.
function getFctMintRate(l1ChainId: 1 | 11155111): Promise<bigint>;
computeFacetTransactionHashComputes a hash for a Facet transaction.
function computeFacetTransactionHash(
l1TransactionHash: Hex,
from: Address,
to: Address,
value: bigint,
data: Hex,
gasLimit: bigint,
mint: bigint
): Hex;
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import { sendFacetTransaction } from "@0xfacet/sdk/viem";
const account = privateKeyToAccount("0xYourPrivateKey");
const client = createWalletClient({
account,
chain: mainnet,
transport: http(),
});
// Send a basic transaction
const hash = await sendFacetTransaction(client, {
to: "0xRecipientAddress",
value: 1000000000000000000n, // 1 FCT
data: "0x", // Empty data for simple FCT transfer
mineBoost: "0x01", // Optional: increase FCT mining amount
});
console.log("Transaction hash:", hash);
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import { writeFacetContract } from "@0xfacet/sdk/viem";
const account = privateKeyToAccount("0xYourPrivateKey");
const client = createWalletClient({
account,
chain: mainnet,
transport: http(),
});
// ERC-20 token transfer example
const hash = await writeFacetContract(client, {
address: "0xTokenContractAddress",
abi: [
{
name: "transfer",
type: "function",
inputs: [
{ name: "recipient", type: "address" },
{ name: "amount", type: "uint256" },
],
outputs: [{ type: "bool" }],
},
],
functionName: "transfer",
args: ["0xRecipientAddress", 1000000000000000000n], // 1 token with 18 decimals
mineBoost: "0x02", // Optional: increase FCT mining amount
});
console.log("Contract transaction hash:", hash);
import { createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import { bridgeAndCall } from "@0xfacet/sdk/viem";
const account = privateKeyToAccount("0xYourPrivateKey");
const client = createWalletClient({
account,
chain: mainnet,
transport: http(),
});
// Bridge ETH and call a contract function
const hash = await bridgeAndCall(
client,
{
address: "0xL2ContractAddress",
abi: [
{
name: "purchaseWithBridgedETH",
type: "function",
inputs: [{ name: "tokenId", type: "uint256" }],
outputs: [],
stateMutability: "payable",
},
],
functionName: "purchaseWithBridgedETH",
args: [123],
},
parseEther("0.1"), // ETH value to bridge
{
// Optional config
maxFeePerGas: 20000000000n,
maxPriorityFeePerGas: 2000000000n,
}
);
console.log("Bridge and call transaction hash:", hash);
import React from "react";
import { parseEther } from "viem";
import { useSendFacetTransaction } from "@0xfacet/sdk/wagmi";
function SendTransaction() {
const { sendFacetTransactionAsync, data } = useSendFacetTransaction();
const handleSend = async () => {
try {
// Using the async version
const hash = await sendFacetTransactionAsync({
to: "0xRecipientAddress",
value: parseEther("0.01"),
mineBoost: "0x01", // Optional: increase FCT mining amount
});
console.log("Transaction submitted:", hash);
} catch (error) {
console.error("Failed to send transaction:", error);
}
};
return <button onClick={handleSend}>Send 0.01 FCT</button>;
}
import React from "react";
import { useWriteFacetContract } from "@0xfacet/sdk/wagmi";
const abi = [
{
name: "mint",
type: "function",
inputs: [
{ name: "to", type: "address" },
{ name: "tokenId", type: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
];
function MintNFT() {
const { writeFacetContractAsync } = useWriteFacetContract({
abi,
address: "0xNFTContractAddress",
functionName: "mint",
});
const handleMint = async () => {
try {
await writeFacetContractAsync({
args: ["0xYourAddress", 123n],
mineBoost: "0x01", // Optional: increase FCT mining amount
});
} catch (error) {
console.error("Mint failed:", error);
}
};
return <button onClick={handleMint}>Mint NFT</button>;
}
import React from "react";
import { parseEther } from "viem";
import { useBridgeAndCall } from "@0xfacet/sdk/wagmi";
function BridgeAndMint() {
const { bridgeAndCall } = useBridgeAndCall();
const handleBridgeAndMint = () => {
bridgeAndCall({
address: "0xL2ContractAddress",
abi: [
{
name: "mintWithBridgedETH",
type: "function",
inputs: [{ name: "tokenId", type: "uint256" }],
outputs: [],
stateMutability: "payable",
},
],
functionName: "mintWithBridgedETH",
args: [123],
ethValue: parseEther("0.1"), // Amount of ETH to bridge from L1 to L2
});
};
return <button onClick={handleBridgeAndMint}>Bridge & Mint</button>;
}
The SDK is fully compatible with standard viem and wagmi methods. Here are some examples:
import { createPublicClient, http } from "viem";
import { facetMainnet } from "@0xfacet/sdk/viem";
const publicClient = createPublicClient({
chain: facetMainnet,
transport: http(),
});
// Standard viem readContract works normally
const balance = await publicClient.readContract({
address: "0xTokenContract",
abi: [
{
name: "balanceOf",
type: "function",
inputs: [{ name: "account", type: "address" }],
outputs: [{ type: "uint256" }],
stateMutability: "view",
},
],
functionName: "balanceOf",
args: ["0xUserAddress"],
});
console.log("Balance:", balance);
import React from "react";
import { useReadContract } from "wagmi";
function TokenBalance() {
const { data: balance } = useReadContract({
address: "0xTokenContract",
abi: [
{
name: "balanceOf",
type: "function",
inputs: [{ name: "account", type: "address" }],
outputs: [{ type: "uint256" }],
stateMutability: "view",
},
],
functionName: "balanceOf",
args: ["0xUserAddress"],
});
return <div>Balance: {balance?.toString() || "Loading..."}</div>;
}
git checkout -b feature/my-featuregit commit -m 'Add new feature'git push origin feature/my-featureThis project is licensed under the MIT License.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.1 | 10 Dec 2024 | 18 | |
| 0.2.0 | 10 Dec 2024 | 18 | |
| 0.1.2 | 10 Dec 2024 | 18 | |
| 0.1.1 | 9 Dec 2024 | 18 | |
| 0.1.0 | 5 Dec 2024 | 18 | |
| 0.0.22 | 20 Nov 2024 | 18 | |
| 0.0.21 | 19 Nov 2024 | 18 | |
| 0.0.20 | 19 Nov 2024 | 18 | |
| 0.0.19 | 13 Nov 2024 | 18 | |
| 0.0.18 | 13 Nov 2024 | 18 | |
| 0.0.17 | 31 Oct 2024 | 18 | |
| 0.0.16 | 31 Oct 2024 | 18 | |
| 0.0.15 | 30 Oct 2024 | 18 | |
| 0.0.14 | 30 Oct 2024 | 18 | |
| 0.0.13 | 28 Oct 2024 | 18 | |
| 0.0.12 | 28 Oct 2024 | 18 | |
| 0.0.11 | 28 Oct 2024 | 18 | |
| 0.0.10 | 28 Oct 2024 | 18 | |
| 0.0.9 | 28 Oct 2024 | 18 | |
| 0.0.8 | 28 Oct 2024 | 18 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 23:08 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:87299481e0c317db83ab1f0658c4723e534d9762b07516169fdf149f3687d48c