π£Migrating from v2.x
Guide for migrating your existing project from use-wallet v2 to v3
The release of @txnlab/use-wallet v3.x marks a significant evolution of the library, transitioning from a React-specific solution to a framework-agnostic core with framework-specific adapters. While we've strived to maintain familiarity and ease of use, there are several important changes to be aware of when upgrading from v2.x.
This guide will walk you through the key differences and provide step-by-step instructions to help you migrate your existing React projects to the new version. By following this guide, you'll be able to take advantage of the improved flexibility and expanded capabilities of v3.x while minimizing disruption to your existing codebase.
Step 1: Update Package Installation
Commands are provided for NPM, Yarn, and PNPM
The first step in migrating to v3.x is to update your package installation. In v3.x, the core functionality has been separated from the React-specific implementation.
Uninstall the existing package:
npm uninstall @txnlab/use-walletyarn remove @txnlab/use-walletpnpm remove @txnlab/use-walletInstall the new React adapter package:
npm install @txnlab/use-wallet-reactyarn add @txnlab/use-wallet-reactpnpm add @txnlab/use-wallet-reactThis new package includes both the core library and the React-specific adapter, ensuring compatibility with your existing React project.
Step 2: Update Library Configuration
In v3.x, the way you configure the library at the root level of your app has changed. The custom hook useInitializeProviders is no longer used, and the configuration is now done outside of the root component using a WalletManager instance.
v2.x Configuration (Old)
v3.x Configuration (New)
Step 3: Update useWallet Hook Usage and Types
useWallet Hook Usage and TypesThe useWallet hook has undergone several changes in v3.x. Here are the key differences and how to adapt your code:
Rename
providerstowallets:In v2.x:
providerswas an array of wallet providers.In v3.x: This is now called
wallets.
Changes in returned properties:
connectedAccountsis nowactiveWalletAccounts.signeris nowtransactionSigner.
Network management:
New properties:
activeNetworkandsetActiveNetworkfor managing the current network.
Algod client:
algodClientandsetAlgodClientare now available directly from the hook.
The types exported by the library have changed as well. Some have changed to fit the new implementation, some have been renamed to be more descriptive and consistent, and others that were outside the scope of the library have been removed.
Wallet accounts:
In v2.x:
Accountwas an object containingproviderId,name,address,authAddr, andemail.In v3.x: This is now called
WalletAccountand only contains anameandaddress.
Wallet providers:
ProvidersArrayis nowSupportedWallets[].PROVIDER_IDenum is renamed toWalletId.BaseClientis nowBaseWallet.Metadatais nowWalletMetadata.
Types that have been removed:
Algorand REST API response types such as
AccountInfoandAsset.Transaction types including
Txn,TxnType,TxnInfo,RawTxnResponse,ConfirmedTxn, andDecodedTransaction.Various other undocumented types that are no longer used with the v3.x implementation.
Note: If you were using a type that was removed in v3.x, you can either redefine it in your application or see if an equivalent type exists in the algosdk or @algorandfoundation/algokit-utils NPM packages.
β’ v2.x types directory: https://github.com/TxnLab/use-wallet/tree/v2/src/types
β’ Algorand JS SDK: https://github.com/algorand/js-algorand-sdk
β’ Algokit TypeScript Utilities: https://github.com/algorandfoundation/algokit-utils-ts
Step 4: Signing and Sending Transactions
Version 3.x introduces improvements in how transactions are signed and sent to the network, aligning more closely with recommended Algorand practices.
Key Changes
Flexible Transaction Formats:
v3.x now accepts both
Uint8Arrayencoded transactions andalgosdk.Transactionobjects.This flexibility simplifies most common use cases.
Improved Atomic Transaction Composer (ATC) Support:
While possible in v2.x, ATC usage is now better supported and documented.
The implementation is more efficient, avoiding unnecessary transaction encoding.
Streamlined API:
Removed several utility functions that were essentially wrappers around
algosdkmethods.Developers are now encouraged to use
algosdkmethods directly for manual transaction handling.
ARC-0001 compliance:
The optional
returnGroupargument has been removed fromsignTransactions, conforming with ARC-0001'sSignTxnsFunctiontype signature. This also simplifies the method's implementation.Now
signTransactionswill always returnPromise<(Uint8Array | null)[]>, a promise that resolves to an array of signed transactions ornullfor transactions that were not signed.
Examples
Signing and Sending Transactions using Atomic Transaction Composer
This example demonstrates the recommended method using an Atomic Transaction Composer, which is now well-supported and efficient.
Manually Signing and Sending Transactions
The next example illustrates how to manually handle transactions if needed, though this is generally less common in typical use cases.
The signTransactions method will still accept an array of Uint8Array encoded transactions, as was required in v2.x (but is no longer necessary).
By adopting these patterns, developers can create more robust and efficient transaction handling in their applications while aligning with best practices in the Algorand ecosystem.
Resources
Technical Support
If you encounter any issues during the migration process or have questions about implementing new features:
Discord Support: Join our NFDomains Discord server, where we have a dedicated #use-wallet channel. Our team and community members are available to provide technical support and answer your questions.
Discord Invite Link: Join NFDomains Discord
Channel: #use-wallet
GitHub Issues: For potential bugs or feature requests, please open an issue on our GitHub repository.
We're here to ensure your transition to v3.x is as smooth as possible. Don't hesitate to reach out β whether you're stuck on a particular migration step, need clarification on new features, or want to discuss best practices for your specific use case.
Last updated

