π§ͺCustom Provider
Detailed guide for creating and implementing a custom provider
Creating a Custom Provider
Step 1: Implement CustomProvider
import { CustomProvider, WalletAccount } from '@txnlab/use-wallet' // Or any framework adapter
class ExampleProvider implements CustomProvider {
/* Required */
async connect(args?: Record<string, any>): Promise<WalletAccount[]> {
// Must return an array of connected accounts
// Optional `args` parameter can be used to pass any additional configuration
}
/* Optional */
async disconnect(): Promise<void> {
// Disconnect from the wallet provider, if necessary
}
/* Optional */
async resumeSession(): Promise<WalletAccount[] | void> {
// Reconnect to the wallet provider when the app mounts, if necessary
// If an array of accounts is returned, they are checked against the stored accounts
// The stored accounts are updated if they differ
}
/* The two signing methods are optional, but you'll want to define at least one! */
async signTransactions<T extends algosdk.Transaction[] | Uint8Array[]>(
txnGroup: T | T[],
indexesToSign?: number[]
): Promise<(Uint8Array | null)[]> {
// Sign transactions with the wallet
// Return array matching length of `txnGroup` with signed transactions or null if unsigned
}
async transactionSigner(
txnGroup: algosdk.Transaction[],
indexesToSign: number[]
): Promise<Uint8Array[]> {
// Sign an array of transaction objects with the wallet
// Return signed transactions only
// Compatible with algosdk's Atomic Transaction Composer
}
}Step 2: Add to WalletManager Configuration
Key Considerations
Last updated