Send Transaction
Sign and send transaction through Blocto.

Sign and Send Transaction

Blocto provides a freemium experience so that they don't have to buy crypto to pay for fees before they try out your dApp (See how meta-transaction works). Hence, your dApps have to sign and send transaction in one-line code so that Blocto is able to pay transaction fee for users.
1
import { SystemProgram, Account, Transaction } from '@solana/web3.js'
2
3
const walletPublicKey = window.solana.publicKey
4
5
const transaction = new Transaction()
6
const instruction = SystemProgram.createAccount({
7
fromPubkey: walletPublicKey,
8
...
9
})
10
transaction.add(instruction)
11
12
const txHash = await window.solana.signAndSendTransaction(transaction)
13
console.log(txHash) // tx hash
Copied!

Convert to Program Wallet Transaction

Sometimes, you probably need to call web3.partialSign to authenticate System Program. Meta-Transaction is going to wrap your instructions into invoke instruction so that it can be sent to program wallet properly. Therefore, your dApps have to call convertToProgramWalletTransaction to the correct message before calling signAndSendTransaction.
1
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash
2
transaction.feePayer = window.solana.publicKey
3
if (signers.length > 0) {
4
transaction = await window.solana.convertToProgramWalletTransaction(transaction)
5
transaction.partialSign(...signers)
6
}
7
8
const txHash = await window.solana.signAndSendTransaction(transaction)
9
console.log(txHash) // tx hash
Copied!
Last modified 6mo ago