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 using Solana web3.
  • 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 SolanaWeb3 as well as the official Solana docs.
Plain Transaction
For plain transactions (no dApp-side signing involved), you can just create transaction with SolanaWeb3 and sign-and-send the transaction with signAndSendTransaction method.
1
val userWalletAddress = "SOLANA_ADDRESS"
2
val transaction = Transaction()
3
4
... // transaction manipulation
5
6
BloctoSDK.shared.solana.signAndSendTransaction(
7
from: userWalletAddress,
8
transaction: transaction) { [weak self] result in
9
guard let self = self else { return }
10
self.resetSetValueStatus()
11
switch result {
12
case let .success(txHash):
13
// handle txHash here
14
case let .failure(error):
15
// handle error here
16
}
17
}
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
val userWalletAddress = "SOLANA_ADDRESS"
2
val transaction = Transaction()
3
4
... // transaction manipulation
5
6
BloctoSDK.shared.solana.convertToProgramWalletTransaction(
7
transaction,
8
solanaAddress: userWalletAddress) { [weak self] result in
9
guard let self = self else { return }
10
switch result {
11
case let .success(transaction):
12
do {
13
var newTransaction = transaction
14
// partial sign after transaction converted.
15
try newTransaction.partialSign(signers: [newAccount])
16
17
BloctoSDK.shared.solana.signAndSendTransaction(
18
from: userWalletAddress,
19
transaction: newTransaction) { [weak self] result in
20
switch result {
21
case let .success(txHash):
22
// handle txHash here
23
case let .failure(error):
24
// handle error here
25
}
26
}
27
} catch {
28
// handle error here
29
}
30
case let .failure(error):
31
// handle error here
32
}
33
}
Copied!
Copy link