Active wallet
The active wallet is the wallet currently being used in your application.
You can view the active wallet using the activeWallet
property from the useWallets
hook.
Or with the useWallet
hook, which is a shorthand for getting the active wallet.
Using openfort wallets
The first thing that any app would want to do is list the wallets linked to the user and show the active wallet.
List user wallets
import { useWallets } from "@openfort/react"
function SampleComponent() {
const {
wallets,
} = useWallets()
// ...
}
This will return a list of UserWallet
objects.
Change active wallet
To change the active wallet, you can use the setActiveWallet
method from the useWallets
hook.
In this example, we change the active wallet by providing the walletId
and address
.
import { useWallets, embeddedWalletId } from "@openfort/react"
import { Hex } from "viem";
function SampleComponent() {
const {
setActiveWallet,
} = useWallets()
const handleChangeWallet = async (address: Hex) => {
const userWallet = await setActiveWallet({
walletId: embeddedWalletId,
address,
});
console.log("Active wallet changed to:", userWallet);
};
// ...
}
This will return the updated UserWallet
object.