The <Transaction /> components provide a high-level wrap around the entire transaction flow. It handles the transaction lifecycle, including gas estimation, fee sponsorship, and status updates.
The <Transaction /> components provide a high-level wrap around the entire transaction flow.
It handles the transaction lifecycle, including gas estimation, fee sponsorship, and status updates.
The Transaction component now supports a simplified shorthand version to streamline the integration process for developers. Instead of manually defining each subcomponent and prop, you can render Transaction without children, and it will automatically include our suggested implementation — complete with the TransactionButton and TransactionToast components.
If you’d like more customization, follow the implementation guide for our Transaction components below.
Copy
Ask AI
// @noErrors: 1109 - Cannot find name 'contracts'import { Transaction } from "@coinbase/onchainkit/transaction"const calls = [...];<Transaction calls={calls} />
Execute one or multiple transactions using the Transaction component. You can pass transactions in either Call or ContractFunctionParameters format. The component will automatically apply batching logic if the user’s wallet supports it.
Take full control of your transactions data with the LifecycleStatus object via the onStatus prop.
This TypeScript object provides statusName and statusData to keep you informed.
Copy
Ask AI
// @noErrors: 2307import { useCallback } from 'react';import { Transaction, TransactionButton, TransactionSponsor, TransactionStatus, TransactionToast, TransactionToastIcon, TransactionToastLabel, TransactionToastAction,} from '@coinbase/onchainkit/transaction';import {contracts} from '@/contracts';// ---cut-before---import type { LifecycleStatus } from '@coinbase/onchainkit/transaction'; // omitted for brevityconst handleOnStatus = useCallback((status: LifecycleStatus) => { console.log('Transaction status:', status); }, []); // omitted for brevity// Usage in component<Transaction contracts={contracts} onStatus={handleOnStatus}> <TransactionButton /> <TransactionSponsor /> <TransactionToast> <TransactionToastIcon /> <TransactionToastLabel /> <TransactionToastAction /> </TransactionToast></Transaction>
The Lifecycle Status features seven states for the transaction experience.
Copy
Ask AI
import type { TransactionError } from "@coinbase/onchainkit/transaction";import type { Address, TransactionReceipt } from "viem";// ---cut-before---type LifecycleStatus = | { statusName: 'init'; statusData: null; } | { statusName: 'error'; statusData: TransactionError; } | { statusName: 'transactionIdle'; // initial status prior to the mutation function executing statusData: null; } | { statusName: 'buildingTransaction'; // resolving calls or contracts promise statusData: null; } | { statusName: 'transactionPending'; // if the mutation is currently executing statusData: null; } | { statusName: 'transactionLegacyExecuted'; statusData: { transactionHashList: string[]; }; } | { statusName: 'success'; // if the last mutation attempt was successful statusData: { transactionReceipts: TransactionReceipt[]; }; };
3
Sponsor with Paymaster capabilities
To sponsor your transactions with Paymaster capabilities, configure your OnchainKitProvider with the appropriate config.paymaster URL, then pass isSponsored={true} to the Transaction component.
Calls also accepts asynchronous functions that are resolved on each button click. This can be useful if you’re calling an API to retrieve transaction data.
These functions must resolve to Call[] or ContractFunctionParameters[].
In the example the calls data will be fetched from api.transaction.com when the user clicks the Transaction Button.