Send Transaction
Once the web application 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 web application 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.js docs 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.js and sign-and-send the transaction with signAndSendTransaction method.
signAndSendTransaction()
request()
1
const transaction = new solanaWeb3.Transaction();
2
...
3
const txHash = await bloctoSDK.solana.signAndSendTransaction(transaction);
Copied!
1
const transaction = new solanaWeb3.Transaction();
2
...
3
bloctoSDK.solana.request({
4
method: 'signAndSendTransaction',
5
params: {
6
message: transaction.serializeMessage().toString('hex')
7
}
8
});
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.
convertToProgramWalletTransaction()
request()
1
const transaction = new solanaWeb3.Transaction();
2
...
3
const converted = await bloctoSDK.solana.convertToProgramWalletTransaction(transaction);
4
const signers = [new solanaWeb3.PublicKey('yourpublickey')];
5
converted.partialSign(...signers);
6
7
const txHash = await bloctoSDK.solana.signAndSendTransaction(converted);
Copied!
1
const transaction = new solanaWeb3.Transaction();
2
...
3
const convertedMessage = await bloctoSDK.solana.request({
4
method: 'convertToProgramWalletTransaction',
5
params: {
6
message: transaction.serializeMessage().toString('hex')
7
}
8
});
9
// convert message to solana Transaction type object
10
const converted = bloctoSDK.solana.toTransaction(convertedMessage);
11
const signers = [new solanaWeb3.PublicKey('yourpublickey')];
12
converted.partialSign(...signers);
13
14
const txHash = await bloctoSDK.solana.request({
15
method: 'signAndSendTransaction',
16
params: {
17
signatures: await solanaSDK.solana.collectSignatures(converted),
18
message: converted.serializeMessage().toString('hex')
19
}
20
});
Copied!
Last modified 5mo ago
Copy link