Solana Web3 SDK for Android. Wallet creation, balance queries, SOL/SPL transfers, signing, and multisig in Kotlin.
SolanaWeb
SolanaWeb is an Android toolbelt for interacting with the Solana network.
[
]
It uses a WebView and JavaScript Bridge to expose Solana capabilities from Kotlin on Android, with support for both callback-based and coroutine-based async APIs.
JitPack.io
We recommend using JitPack to add the library:
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Elizabet1926:solana-web3:1.0.1'
}
1. Setup & Initialization
Create a SolanaWeb instance and call setup (or setupAsync) before using any other APIs. The setup loads the embedded WebView and JS environment. When you are done, call release() to free resources.
val solanaWeb = SolanaWeb(context)
solanaWeb.showLog = true // Optional: enable Bridge / WebView logs
// Callback style solanaWeb.setup { success, error -> if (success) { Log.d("SolanaWeb", "Initialization successful") } else { Log.e("SolanaWeb", "Initialization failed: $error") } }
// Or with Coroutines lifecycleScope.launch { val (success, error) = solanaWeb.setupAsync() if (success) { Log.d("SolanaWeb", "Initialization successful") } else { Log.e("SolanaWeb", "Initialization failed: $error") } }
// Release when no longer needed solanaWeb.release()
2. Wallet Management
Create Random Wallet
val response = solanaWeb.createWalletAsync(wordCount = 12, language = "en")
// Returns mnemonic, privateKey, publicKey, address, etc.
Import Account from Mnemonic
val mnemonic = "word1 word2 ..."
val response = solanaWeb.importAccountFromMnemonicAsync(mnemonic)
Import Account from Private Key
val privateKey = "your-private-key"
val response = solanaWeb.importAccountFromPrivateKeyAsync(privateKey)
3. Balance & Tokens
Get SOL Balance
val response = solanaWeb.getSOLBalanceAsync(
endpoint = "https://api.mainnet-beta.solana.com",
address = "YourPublicKey"
)
// response["balance"] holds the SOL balance
Get SPL Token Balance
val response = solanaWeb.getSPLTokenBalanceAsync(
endpoint = "https://api.mainnet-beta.solana.com",
address = "YourPublicKey",
SPLTokenAddress = "TokenMintAddress",
decimalPoints = 6 // optional
)
Get Token Accounts by Owner
val response = solanaWeb.getTokenAccountsByOwnerAsync(
endpoint = "https://api.mainnet-beta.solana.com",
address = "YourPublicKey"
)
4. Transfers
SOL Transfer
val response = solanaWeb.solanaMainTransferAsync(
endpoint = "https://api.mainnet-beta.solana.com",
secretKey = "SenderPrivateKey",
toPublicKey = "ReceiverPublicKey",
amount = 0.5
)
Estimate SOL Transfer Cost
val response = solanaWeb.estimatedSOLTransferCostAsync(
endpoint = "https://api.mainnet-beta.solana.com",
fromPublicKey = "FromPublicKey",
toPublicKey = "ToPublicKey",
amount = 0.5
)
SPL Token Transfer
val response = solanaWeb.solanaTokenTransferAsync(
endpoint = "https://api.mainnet-beta.solana.com",
secretKey = "SenderPrivateKey",
toPublicKey = "ReceiverPublicKey",
mintAuthority = "TokenMintAddress",
amount = 100,
decimals = 6 // optional
)
Estimate SPL Token Transfer Cost
val response = solanaWeb.estimatedSPLTokenTransferCostAsync(
endpoint = "https://api.mainnet-beta.solana.com",
toPublicKey = "ToPublicKey",
mint = "TokenMintAddress",
amount = 100,
fromPublicKey = "FromPublicKey", // optional
privateKey = "PrivateKey", // optional
decimals = 6 // optional
)
5. Message Signing & Verification
Sign Message
val response = solanaWeb.signMessageAsync(
privateKey = "YourPrivateKey",
message = "Hello Solana",
encoding = "utf8" // optional
)
// Returns signature result
Verify Signature
val response = solanaWeb.verifySignatureAsync(
publicKey = "ExpectedPublicKey",
message = "Hello Solana",
signature = "SignatureHex",
encoding = "utf8" // optional
)
// Returns whether verification passed
6. Multisig
Create Multisig Account
val response = solanaWeb.createMultisigAsync(
endpoint = "https://api.mainnet-beta.solana.com",
creatorPrivateKey = "CreatorPrivateKey",
members = listOf("Member1PublicKey", "Member2PublicKey"),
threshold = 2,
name = "MyMultisig" // optional
)
Proposal Activate
val response = solanaWeb.proposalActivateAsync(
endpoint = "https://api.mainnet-beta.solana.com",
memberPrivateKey = "MemberPrivateKey",
multisigPda = "MultisigPdaAddress",
transactionIndex = 0L
)
Proposal Approve
val response = solanaWeb.proposalApproveAsync(
endpoint = "https://api.mainnet-beta.solana.com",
memberPrivateKey = "MemberPrivateKey",
multisigPda = "MultisigPdaAddress",
transactionIndex = 0L
)
Execute Vault Transaction
val response = solanaWeb.vaultTransactionExecuteAsync(
endpoint = "https://api.mainnet-beta.solana.com",
memberPrivateKey = "MemberPrivateKey",
multisigPda = "MultisigPdaAddress",
transactionIndex = 0L,
vaultIndex = 0 // optional
)
Get Proposal Status
val response = solanaWeb.getProposalStatusAsync(
endpoint = "https://api.mainnet-beta.solana.com",
multisigPda = "MultisigPdaAddress",
transactionIndex = 0L
)
Multisig Send SOL
val response = solanaWeb.multisigSendSOLAsync(
endpoint = "https://api.mainnet-beta.solana.com",
creatorPrivateKey = "CreatorPrivateKey",
multisigPda = "MultisigPdaAddress",
to = "ReceiverPublicKey",
amountSol = 1.0,
vaultIndex = 0, // optional
transactionIndex = null // optional; pass null when assigned by backend
)
Multisig Send SPL Token
val response = solanaWeb.multisigSendSPLTokenAsync(
endpoint = "https://api.mainnet-beta.solana.com",
creatorPrivateKey = "CreatorPrivateKey",
multisigPda = "MultisigPdaAddress",
mint = "TokenMintAddress",
to = "ReceiverPublicKey",
amount = 100,
decimals = 6, // optional
createAtaIfMissing = true, // optional
vaultIndex = 0, // optional
transactionIndex = null // optional
)
Error Handling
All async methods return Map<String, Any>?. Check the state or error fields to determine success or failure:
val response = solanaWeb.getSOLBalanceAsync(endpoint, address)
if (response != null) {
val state = response["state"] as? Boolean ?: false
if (state) {
val balance = response["balance"]
Log.d("SolanaWeb", "Balance: $balance")
} else {
val error = response["error"] as? String ?: "Unknown error"
Log.e("SolanaWeb", "Error: $error")
}
}
License
SolanaWeb is open source under the MIT license. See LICENSE for details.