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 walletwallet
- The wallet to connect toaccountAddress
- (optional) The address in the wallet to connect to
-
options
- Options passed the theuseMutation
hook from @tanstack/react-query (opens in a new tab)