Skip to main content

attachCheckoutTransactionSource

Attaches a wallet source to a checkout transaction. This tells the checkout system which wallet address and chain the payment will come from, enabling accurate quote generation. Call this after createCheckoutTransaction and before getCheckoutTransactionQuote.

Usage

import {
  attachCheckoutTransactionSource,
  getActiveNetworkData,
} from '@dynamic-labs-sdk/client';

const { networkData } = await getActiveNetworkData({ walletAccount });

const transaction = await attachCheckoutTransactionSource({
  transactionId: 'txn_abc123',
  fromAddress: walletAccount.address,
  fromChainId: networkData?.networkId ?? '',
  fromChainName: walletAccount.chain,
});

Parameters

ParameterTypeDescription
transactionIdstringThe checkout transaction ID returned by createCheckoutTransaction.
fromAddressstringThe wallet address that will fund the transaction.
fromChainIdstringThe network ID of the source chain (e.g., '1' for Ethereum mainnet, '137' for Polygon).
fromChainNameChainThe blockchain chain (e.g., 'EVM', 'SOL').

Returns

Promise<CheckoutTransaction> - The updated transaction with the source wallet attached.

Examples

Attach an EVM wallet

import {
  attachCheckoutTransactionSource,
  getActiveNetworkData,
  getWalletAccounts,
} from '@dynamic-labs-sdk/client';

const walletAccounts = getWalletAccounts();
const wallet = walletAccounts[0];
const { networkData } = await getActiveNetworkData({ walletAccount: wallet });

await attachCheckoutTransactionSource({
  transactionId: 'txn_abc123',
  fromAddress: wallet.address,
  fromChainId: networkData?.networkId ?? '1',
  fromChainName: wallet.chain,
});

Attach a Solana wallet

import { attachCheckoutTransactionSource } from '@dynamic-labs-sdk/client';

await attachCheckoutTransactionSource({
  transactionId: 'txn_abc123',
  fromAddress: 'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
  fromChainId: 'mainnet-beta',
  fromChainName: 'SOL',
});