@evefrontier/dapp-kit - v0.1.9
    Preparing search index...

    Function useSponsoredTransaction

    • Hook for executing gas-sponsored transactions via EVE Frontier.

      This mutation hook enables dApps to send transactions where gas fees are paid by the EVE Frontier backend service, eliminating the need for users to have SUI tokens for gas. The wallet must support the evefrontier:sponsoredTransaction feature (currently only EVE Vault).

      Transient server errors (e.g. 502 Bad Gateway) are retried automatically with the same payload a limited number of times with a delay between attempts.

      The hook automatically uses the currently connected wallet and account (unless overridden) and handles wallet feature detection and validation.

      Input (passed to mutate / mutateAsync):

      • txAction (required) – The sponsored action to run (e.g. BRING_ONLINE, BRING_OFFLINE).
      • chain (required) – Sui chain id, e.g. "sui:testnet" or "sui:mainnet".
      • assembly (required) – Full assembly object (AssemblyType<Assemblies>). Must include type and item_id (number). If item_id is missing or invalid, the hook falls back to the URL query param itemId (parsed as a non-negative integer). Fails with AssemblyIdRequiredError if neither source provides a valid id.
      • tenant (optional) – Tenant ID. When omitted, the hook resolves it from the URL query param (e.g. tenant) with fallback to TenantId.UTOPIA. Pass explicitly to override.
      • account (optional) – Signer address. If omitted, the currently connected wallet account is used.

      Output (on success, in data or resolved from mutateAsync):

      • digest (required) – Transaction digest.
      • effects (optional) – Transaction effects, BCS encoded.
      • rawEffects (optional) – Raw effects bytes.

      Parameters

      Returns UseMutationResult<
          SponsoredTransactionOutput,
          UseSponsoredTransactionError,
          SponsoredTransactionArgs,
      >

      React Query mutation result with:

      • mutate(args, options?) - Trigger transaction (fire-and-forget)
      • mutateAsync(args) - Trigger transaction (returns Promise)
      • isPending - True while the transaction is in progress
      • isError - True if the last mutation failed
      • error - Error from the last failed mutation
      • data - Last successful result (SponsoredTransactionOutput)

      If no wallet is connected

      If no account is selected

      If wallet doesn't support sponsored transactions

      If assembly ID is missing or invalid (neither assembly.item_id nor itemId query param is a valid non-negative integer)

      import { useSponsoredTransaction, SponsoredTransactionActions, useSmartObject } from "@evefrontier/dapp-kit";

      const BringOnlineButton = () => {
      const { assembly } = useSmartObject();
      const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();

      const handleBringOnline = async () => {
      if (!assembly) return;
      try {
      const result = await sendTx({
      txAction: SponsoredTransactionActions.BRING_ONLINE,
      assembly,
      chain: "sui:testnet",
      });
      console.log("Transaction digest:", result.digest);
      } catch (error) {
      console.error("Transaction failed:", error);
      }
      };

      return (
      <button onClick={handleBringOnline} disabled={isPending || !assembly}>
      {isPending ? "Processing..." : "Bring Online"}
      </button>
      );
      };
      const { assembly } = useSmartObject();
      const { mutate: sendTx } = useSponsoredTransaction();

      sendTx(
      {
      txAction: SponsoredTransactionActions.BRING_ONLINE,
      assembly,
      chain: "sui:testnet",
      },
      {
      onSuccess: (result) => {
      notify({ type: Severity.Success, txHash: result.digest });
      },
      onError: (error) => {
      notify({ type: Severity.Error, message: error.message });
      },
      }
      );
      const result = await sendTx({
      txAction: SponsoredTransactionActions.BRING_ONLINE,
      assembly, // full AssemblyType from useSmartObject() or similar
      chain: "sui:testnet",
      account: "0x...", // optional; defaults to connected wallet account
      });