Transaction Provider
The Transaction Provider component supplies the necessary context for managing on-chain transactions within the application. It provides state management and utility functions for handling transaction modals, batching, and more.
The TransactionProvider must wrap any components that need access to transaction context, including the TransactionModal component.
Add to your project
import { TransactionProvider } from 'identity-kit/src/context/transactionContext'
export default function App() {
return <TransactionProvider>{/* Your application components */}</TransactionProvider>
}
Parameters
Parameter | Description | Required | Default Value |
---|---|---|---|
batchTransactions | Enables batching of transactions if set to true. | No | false |
paymasterService | The paymaster service to use for sponsored transactions. (string) | No | - |
defaultChainId | The default chain ID to use for the transaction provider. (number) | No | - |
children | The child components that will have access to the transaction context. | Yes | - |
Usage
The TransactionProvider
component is used to wrap parts of your application that require access to transaction-related state and functions. It manages the state of transaction modals, pending transactions, and provides utility functions for transaction operations.
Features
- Transaction Modal Management: Controls the visibility and state of transaction modals.
- Batch Transactions: Supports batching of multiple transactions for a streamlined user experience.
- Default Chain ID: The default chain ID to use if the user does not have an EFP list yet (Has to mint the new list).
- Transaction State Management: Provides state and functions for managing pending transactions, current transaction index, and more.
- Paymaster Service: Supports paymaster services for sponsored transactions.
The provider supports paymaster services for sponsored transactions. See the Coinbase Paymaster documentation for more details.
Batching Transactions
If you set batchTransactions
to true
, the TransactionProvider
will manage a batch of transactions. This will allow you to either execute transactions one by one or batch them together and have a cart-like experience.
<TransactionProvider batchTransactions={true}>
<YourComponent />
</TransactionProvider>
You will have to provide a button in your application that will open the transaction modal.
import { useTransactions } from 'ethereum-identity-kit'
/* ... your code ... */
const { setTxModalOpen } = useTransactions()
<button onClick={() => setTxModalOpen(true)}>Open Transaction Modal</button>
/* ... your code ... */
Context Values
The TransactionProvider
supplies the following context values:
txModalOpen
: Boolean indicating if the transaction modal is open.batchTransactions
: Boolean indicating if transactions are batched.pendingTxs
: Array of pending transactions.currentTxIndex
: Index of the current transaction being processed.selectedChainId
: ID of the selected blockchain network.addTransactions
: Function to add new transactions.resetTransactions
: Function to reset all transactions.goToNextTransaction
: Function to proceed to the next transaction.lists
: The EFP lists of the connected user.listsLoading
: Boolean indicating if the EFP lists of the connected user are loading.
Notes
Ensure that the TransactionProvider
wraps components that need access to transaction context.
The batchTransactions
parameter determines if transactions should be batched. When enabled, it provides a cart-like
experience for managing multiple transactions.