Write a helper method buildTransferTransaction that handles creating the transfer instruction and assembling it into a Transaction.You can use the SystemProgram.transfer util method provided by web3-solana to conveniently generate a serialized transfer instruction.
Assuming you do not currently have the user’s wallet address available, you can use Mobile Wallet Adapter
to connect to their mobile wallet app, and learn what their wallet address is.
import com.funkatronics.encoders.Base58import com.solana.publickey.SolanaPublicKeyimport com.solana.mobilewalletadapter.clientlib.*import com.solana.rpc.SolanaRpcClientimport com.solana.networking.KtorNetworkDriver // `this` is the current Android activityval sender = ActivityResultSender(this)// Instantiate the MWA client objectval walletAdapter = MobileWalletAdapter(/* ... */)val lamportAmount = 1000000val result = walletAdapter.transact(sender) { authResult -> // Retrieve the user wallet address from the MWA authResult val userAccountAddress = SolanaPublicKey(authResult.accounts.first().publicKey) // Fetch latest blockhash val rpcClient = SolanaRpcClient("https://api.devnet.solana.com", KtorNetworkDriver()) val blockhashResponse = rpcClient.getLatestBlockhash() // Use the wallet address to build the transfer transaction val transferTx = buildTransferTransaction( blockhashResponse.result!!.blockhash, userAccountAddress, SolanaPublicKey("<address_of_recipient>"), lamportAmount ); // ...}
Finally, issue a signAndSendTransactions request, prompting the user to sign the transfer transaction
and submit it to the network.
import com.funkatronics.encoders.Base58import com.solana.publickey.SolanaPublicKeyimport com.solana.mobilewalletadapter.clientlib.* // `this` is the current Android activityval sender = ActivityResultSender(this)// Instantiate the MWA client objectval walletAdapter = MobileWalletAdapter(/* ... */)val result = walletAdapter.transact(sender) { authResult -> // Build a transaction using web3-solana classes val userAccountAddress = SolanaPublicKey(authResult.accounts.first().publicKey) // Fetch latest blockhash val rpcClient = SolanaRpcClient("https://api.devnet.solana.com", KtorNetworkDriver()) val blockhashResponse = rpcClient.getLatestBlockhash() // Use the wallet address to build the transfer transaction val transferTx = buildTransferTransaction( blockhashResponse.result!!.blockhash, userAccountAddress, SolanaPublicKey("<address_of_recipient>"), lamportAmount ); // Issue a 'signTransactions' request signAndSendTransactions(arrayOf(transferTx.serialize()));}// Read the results!when (result) { is TransactionResult.Success -> { val txSignatureBytes = result.successPayload?.signatures?.first() txSignatureBytes?.let { println("Transaction signature: " + Base58.encodeToString(signedTxBytes)) } } is TransactionResult.NoWalletFound -> { println("No MWA compatible wallet app found on device.") } is TransactionResult.Failure -> { println("Error during signing and sending transactions: " + result.e.message) }}
If signing is successful, you can check the returned result for the transaction signature, or handle failure cases.
Check out the Kotlin Compose Scaffold for a code examples of what is discussed in this guide, and an easy launching point to getting started with Solana Kotlin development!
Last modified on May 27, 2026
⌘I
Assistant
Responses are generated using AI and may contain mistakes.