Send Transaction
Make sure you initialize Blocto SDK first
Once your app is connected to Blocto wallet, it can send transactions on behalf of the user, with the user's permission.
In order to send a transaction, the app must:
  • Create an unsigned transaction or transactions.
  • Have it be signed by the user's Blocto wallet.
  • Send it with Blocto custom JSON-RPC.
For more information about the transactions on Solana, it is recommended to check out the solana-web3.kotlin as well as the official Solana docs.
Plain Transaction
For plain transactions (no dApp-side signing involved), you can just create transaction with solana-web3.kotlin and sign-and-send the transaction with signAndSendTransaction method.
1
val address = "SOLANA_ADDRESS"
2
val transaction = Transaction()
3
​
4
... // transaction manipulation
5
​
6
BloctoSDK.solana.signAndSendTransaction(
7
context = context,
8
fromAddress = address,
9
transaction = transaction,
10
onSuccess = { txHash ->
11
// transaction sent
12
},
13
onError = { error ->
14
// handle error
15
}
16
)
Copied!
Partial Sign Transaction
For transactions involving dApp-side signing, first you need to convert the transaction to our wallet-compatible format by calling convertToProgramWalletTransaction, and sign the instructions with your keys, then sign-and-send the partial-signed transaction with our signAndSendTransaction method.
1
suspend fun convertToProgramWalletTransaction(
2
address: String,
3
transaction: Transaction
4
): Transaction = withContext(Dispatchers.Default) {
5
BloctoSDK.solana.convertToProgramWalletTransaction(address, transaction)
6
}
7
​
8
lifecycleScope.launch {
9
val address = "SOLANA_ADDRESS"
10
val signer = KeyPair.generate()
11
val transaction = Transaction()
12
​
13
... // transaction manipulation
14
​
15
val convertedTransaction = convertToProgramWalletTransaction(
16
address = address,
17
transaction = transaction
18
)
19
convertedTransaction.partialSign(signer)
20
​
21
BloctoSDK.solana.signAndSendTransaction(
22
context = context,
23
fromAddress = address,
24
transaction = convertedTransaction,
25
onSuccess = { txHash ->
26
// transaction sent
27
},
28
onError = { error ->
29
// handle error
30
}
31
)
32
}
Copied!
BloctoSDK.solana.convertToProgramWalletTransaction(...) method need to be executed in the background thread.
Copy link