dAppBooster
    Preparing search index...
    • Custom hook to send a cross-domain message from L1 (Ethereum Mainnet or Sepolia) to Optimism.

      Handles the complex process of sending a message from L1 to L2 through Optimism's CrossDomainMessenger contract, including:

      • Estimating gas on both L1 and L2
      • Encoding function data for the message
      • Adding safety buffer to gas estimates (20%)
      • Executing the cross-chain transaction

      Parameters

      • params: {
            args:
                | readonly []
                | readonly [`0x${string}`, boolean]
                | readonly [`0x${string}`, `0x${string}`]
                | readonly [`0x${string}`, `0x${string}`, `0x${string}`, bigint]
                | readonly [`0x${string}`, `0x${string}`, `0x${string}`]
                | readonly [
                    `0x${string}`,
                    `0x${string}`,
                    `0x${string}`,
                    `0x${string}`,
                    bigint,
                ]
                | readonly [`0x${string}`, bigint]
                | readonly [`0x${string}`, `0x${string}`, bigint]
                | readonly [boolean]
                | readonly [`0x${string}`]
                | readonly [readonly `0x${string}`[], `0x${string}`]
                | readonly [`0x${string}`, bigint, bigint, number]
                | readonly [`0x${string}`, `0x${string}`, number]
                | readonly [`0x${string}`, bigint, bigint, `0x${string}`]
                | readonly [`0x${string}`, bigint, `0x${string}`]
                | readonly [
                    `0x${string}`,
                    bigint,
                    `0x${string}`,
                    bigint,
                    number,
                    `0x${string}`,
                    `0x${string}`,
                ];
            contractName: | "ERC20"
            | "SpecialERC20WithAddress"
            | "EnsRegistry"
            | "AaveFaucet"
            | "AAVEWeth"
            | "OPL1CrossDomainMessengerProxy";
            fromChain: {}
            | {};
            functionName:
                | "setApprovalForAll"
                | "setOwner"
                | "setRecord"
                | "setResolver"
                | "setSubnodeOwner"
                | "setSubnodeRecord"
                | "setTTL"
                | "mint"
                | "renounceOwnership"
                | "setMintable"
                | "setPermissioned"
                | "transferOwnership"
                | "transferOwnershipOfChild"
                | "borrowETH"
                | "depositETH"
                | "emergencyEtherTransfer"
                | "emergencyTokenTransfer"
                | "repayETH"
                | "withdrawETH"
                | "withdrawETHWithPermit"
                | "sendMessage"
                | "approve"
                | "transfer"
                | "transferFrom";
            l2ContractAddress: `0x${string}`;
            value: bigint;
        }

        The parameters object

        • args:
              | readonly []
              | readonly [`0x${string}`, boolean]
              | readonly [`0x${string}`, `0x${string}`]
              | readonly [`0x${string}`, `0x${string}`, `0x${string}`, bigint]
              | readonly [`0x${string}`, `0x${string}`, `0x${string}`]
              | readonly [
                  `0x${string}`,
                  `0x${string}`,
                  `0x${string}`,
                  `0x${string}`,
                  bigint,
              ]
              | readonly [`0x${string}`, bigint]
              | readonly [`0x${string}`, `0x${string}`, bigint]
              | readonly [boolean]
              | readonly [`0x${string}`]
              | readonly [readonly `0x${string}`[], `0x${string}`]
              | readonly [`0x${string}`, bigint, bigint, number]
              | readonly [`0x${string}`, `0x${string}`, number]
              | readonly [`0x${string}`, bigint, bigint, `0x${string}`]
              | readonly [`0x${string}`, bigint, `0x${string}`]
              | readonly [
                  `0x${string}`,
                  bigint,
                  `0x${string}`,
                  bigint,
                  number,
                  `0x${string}`,
                  `0x${string}`,
              ]

          Arguments to pass to the L2 function

        • contractName:
              | "ERC20"
              | "SpecialERC20WithAddress"
              | "EnsRegistry"
              | "AaveFaucet"
              | "AAVEWeth"
              | "OPL1CrossDomainMessengerProxy"

          Name of the contract from contracts registry

        • fromChain: {} | {}

          Source chain (sepolia or mainnet)

        • functionName:
              | "setApprovalForAll"
              | "setOwner"
              | "setRecord"
              | "setResolver"
              | "setSubnodeOwner"
              | "setSubnodeRecord"
              | "setTTL"
              | "mint"
              | "renounceOwnership"
              | "setMintable"
              | "setPermissioned"
              | "transferOwnership"
              | "transferOwnershipOfChild"
              | "borrowETH"
              | "depositETH"
              | "emergencyEtherTransfer"
              | "emergencyTokenTransfer"
              | "repayETH"
              | "withdrawETH"
              | "withdrawETHWithPermit"
              | "sendMessage"
              | "approve"
              | "transfer"
              | "transferFrom"

          Name of function to call on the L2 contract

        • l2ContractAddress: `0x${string}`

          Target contract address on L2

        • value: bigint

          Value in wei to send with the transaction

      Returns () => Promise<`0x${string}`>

      Async function that executes the cross-domain message when called

      const sendToOptimism = useL1CrossDomainMessengerProxy({
      fromChain: sepolia,
      l2ContractAddress: '0x...',
      contractName: 'MyContract',
      functionName: 'myFunction',
      args: [arg1, arg2],
      value: parseEther('0.1')
      });

      // Later in your code
      const handleClick = async () => {
      try {
      const txHash = await sendToOptimism();
      console.log('Transaction sent:', txHash);
      } catch (error) {
      console.error('Failed to send cross-domain message:', error);
      }
      };