React Native SDK
useWallet
API reference for the useWallet hook.
useWallet
The useWallet hook provides methods to interact with the wallet on mobile.
import { useWallet } from '@lazorkit/wallet-mobile-adapter';connect
Connects to the wallet, triggering a deep link to the portal if necessary.
Usage
const { connect } = useWallet();
await connect({
redirectUrl: 'myapp://home',
onSuccess: (wallet) => console.log('Connected:', wallet.smartWallet),
onFail: (error) => console.error('Connection failed:', error)
});Arguments
| Property | Type | Required | Description |
|---|---|---|---|
options | object | Yes | Connection options. |
options.redirectUrl | string | Yes | App deep link for callbacks. |
options.onSuccess | (wallet: WalletInfo) => void | No | Callback on success. |
options.onFail | (error: Error) => void | No | Callback on error. |
disconnect
Disconnects the wallet session locally.
Usage
const { disconnect } = useWallet();
await disconnect({
onSuccess: () => console.log('Disconnected'),
onFail: (e) => console.error(e)
});Arguments
| Property | Type | Required | Description |
|---|---|---|---|
options | object | No | Disconnect options. |
options.onSuccess | () => void | No | Callback on success. |
options.onFail | (error: Error) => void | No | Callback on error. |
signMessage
Signs a message via the portal.
Usage
const { signMessage } = useWallet();
await signMessage('Hello', {
redirectUrl: 'myapp://callback',
onSuccess: (res) => console.log('Signature:', res.signature),
onFail: (err) => console.error('Signing failed:', err)
});Arguments
| Property | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Message to sign. |
options | object | Yes | Options object. |
options.redirectUrl | string | Yes | App deep link. |
options.onSuccess | (res: { signature: string }) => void | No | Callback on success. |
options.onFail | (error: Error) => void | No | Callback on error. |
Returns
Promise<{ signature: string; signedPayload: string }> - Object containing the signature and signed payload.
signAndSendTransaction
Signs and sends a transaction.
Usage
Usage
const { signAndSendTransaction } = useWallet();
await signAndSendTransaction(
{
instructions: [/* ... */],
transactionOptions: {
feeToken: 'USDC',
computeUnitLimit: 500_000,
}
},
{
redirectUrl: 'myapp://callback',
onSuccess: (sig) => console.log('Tx Configured:', sig),
onFail: (err) => console.error('Tx Failed:', err)
}
);Arguments
| Property | Type | Required | Description |
|---|---|---|---|
payload | object | Yes | Transaction payload. |
payload.instructions | TransactionInstruction[] | Yes | Array of instructions. |
payload.transactionOptions | object | Yes | Config options. |
transactionOptions.feeToken | string | No | Token address for gas fees (e.g. USDC). |
transactionOptions.computeUnitLimit | number | No | Max compute units for the transaction. |
transactionOptions.addressLookupTableAccounts | AddressLookupTableAccount[] | No | Lookup tables for versioned (v0) transactions. |
transactionOptions.clusterSimulation | 'devnet' | 'mainnet' | Yes | Network to use for simulation. |
options | object | Yes | Options object. |
options.redirectUrl | string | Yes | App deep link. |
options.onSuccess | (sig: string) => void | No | Callback on success. |
options.onFail | (error: Error) => void | No | Callback on error. |
Returns
Promise<string> - The transaction signature.