@0xfacet/sdk
Version:
A toolkit for Facet blockchain integration.
39 lines (38 loc) • 2.29 kB
TypeScript
import { Abi, Account, Chain, Client, ContractFunctionArgs, ContractFunctionName, Transport, WriteContractParameters, WriteContractReturnType } from "viem";
import { BridgeAndCallConfig } from "../types";
/**
* Bridges ETH from L1 to L2 and executes a contract call on Facet (L2).
*
* This function handles the complexities of bridging ETH from L1 to L2 and executing a contract call
* on the Facet network. It includes transaction simulation, gas estimation, and proper encoding of
* the bridged transaction data.
*
* @template chain - The chain type for the client
* @template account - The account type for the client
* @template abi - The ABI type for the contract
* @template functionName - The name of the function to call
* @template args - The arguments for the function call
* @template chainOverride - Optional chain override type
*
* @param client - The viem client instance used to interact with the blockchain
* @param parameters - The contract parameters, following viem's WriteContractParameters format
* @param ethValue - The amount of ETH to bridge (in wei)
* @param config - Optional configuration object for contract addresses
*
* @returns A promise that resolves to the Facet transaction hash
*
* @throws Will throw if no account is provided
* @throws Will throw if the network is unsupported
* @throws Will throw if contract addresses are not available
* @throws Will throw if the transaction simulation fails
* @throws Will throw and properly format any contract-related errors
*
* @example
* const hash = await bridgeAndCall(client, {
* address: '0x...',
* abi: contractAbi,
* functionName: 'someFunction',
* args: [arg1, arg2]
* }, parseEther('0.1'));
*/
export declare function bridgeAndCall<chain extends Chain | undefined, account extends Account | undefined, const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "nonpayable" | "payable">, args extends ContractFunctionArgs<abi, "nonpayable" | "payable", functionName>, chainOverride extends Chain | undefined>(client: Client<Transport, chain, account>, parameters: WriteContractParameters<abi, functionName, args, chain, account, chainOverride>, ethValue: bigint, config?: BridgeAndCallConfig): Promise<WriteContractReturnType>;