Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

Use isEvmGasSponsorshipEnabled to check if EVM gas sponsorship is enabled in your project settings before attempting to send sponsored transactions.

Usage

import {
  isEvmGasSponsorshipEnabled,
  sendSponsoredTransaction,
} from '@dynamic-labs-sdk/evm';
import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';

const send = async (walletAccount, calls, transaction) => {
  if (isEvmGasSponsorshipEnabled()) {
    // Use sponsored transaction
    const { transactionHash } = await sendSponsoredTransaction({
      walletAccount,
      calls,
    });
    return transactionHash;
  }

  // Fall back to a regular user-paid transaction via viem
  const walletClient = await createWalletClientForWalletAccount({ walletAccount });
  return walletClient.sendTransaction(transaction);
};

Return value

TypeDescription
booleantrue if EVM gas sponsorship is enabled, false otherwise

Requirements

  • A Dynamic Client must be initialized before calling this function
  • EVM gas sponsorship must be enabled in the Dynamic Dashboard under Settings > Embedded Wallets

React

isEvmGasSponsorshipEnabled is synchronous and works the same in React. Use it inside a button handler to decide which send path to take:
import {
  isEvmGasSponsorshipEnabled,
  sendSponsoredTransaction,
  isEvmWalletAccount,
} from '@dynamic-labs-sdk/evm';
import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';

function SendButton({ calls, transaction }) {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isEvmWalletAccount);

  const handleSend = async () => {
    if (!walletAccount) return;

    if (isEvmGasSponsorshipEnabled()) {
      await sendSponsoredTransaction({ walletAccount, calls });
      return;
    }

    const walletClient = await createWalletClientForWalletAccount({ walletAccount });
    await walletClient.sendTransaction(transaction);
  };

  return (
    <button onClick={handleSend} disabled={!walletAccount}>
      Send {isEvmGasSponsorshipEnabled() ? '(Sponsored)' : ''}
    </button>
  );
}