useConnectWallet
The useConnectWallet
hook is a mutation hook for establishing a connection to a specific wallet.
import { ConnectButton, useConnectWallet, useWallets } from '@mysten/dapp-kit';
function MyComponent() {
const wallets = useWallets();
const { mutate: connect } = useConnectWallet();
return (
<div style={{ padding: 20 }}>
<ConnectButton />
<ul>
{wallets.map((wallet) => (
<li key={wallet.name}>
<button
onClick={() => {
connect(
{ wallet },
{
onSuccess: () => console.log('connected'),
},
);
}}
>
Connect to {wallet.name}
</button>
</li>
))}
</ul>
</div>
);
}
Example
Connect arguments
-
args
- Arguments passed to theconnect
function of the wallet.wallet
- The wallet to connect to.accountAddress
- (optional) The address in the wallet to connect to.
-
options
- Options passed the theuseMutation
hook from @tanstack/react-query (opens in a new tab).