Usage examples for connecting to wallets, signing messages, and sending transactions with the Kotlin MWA client.
This page demonstrates how to use each method from the MobileWalletAdapter client. Make sure you have completed the Installation and Setup steps first.
Use connect to establish a wallet connection. On success, the TransactionResult contains an AuthorizationResult with the user’s wallet address and auth token.
import com.solana.mobilewalletadapter.clientlib.*val sender = ActivityResultSender(this)val walletAdapter = MobileWalletAdapter(/* ... */)val result = walletAdapter.connect(sender)when (result) { is TransactionResult.Success -> { val authResult = result.authResult println("Connected to: " + authResult.accounts.first().publicKey) } is TransactionResult.NoWalletFound -> { println("No MWA compatible wallet app found on device.") } is TransactionResult.Failure -> { println("Error connecting to wallet: " + result.e.message) }}
Use disconnect to revoke authorization and invalidate the stored auth token:
Use signIn to connect to a wallet and verify ownership in a single step. This combines authorization and message signing into one user interaction.
import com.solana.mobilewalletadapter.clientlib.*val sender = ActivityResultSender(this)val walletAdapter = MobileWalletAdapter(/* ... */)val result = walletAdapter.signIn( sender, SignInWithSolana.Payload("yourdomain.com", "Sign in to My App"))when (result) { is TransactionResult.Success -> { val signInResult = result.authResult.signInResult println("Signed in successfully") } is TransactionResult.NoWalletFound -> { println("No MWA compatible wallet app found on device.") } is TransactionResult.Failure -> { println("Error signing in: " + result.e.message) }}
To sign in and continue issuing additional requests in the same session, include the signInPayload parameter with transact:
val result = walletAdapter.transact(sender, SignInWithSolana.Payload("yourdomain.com", "Sign in to My App")) { authResult -> /* Send additional MWA requests here */}