Skip to main content

Sign Transaction

Client is listening to the event client.on('signTransactions'), which returns data about transactions that are being requested.

When user accepts and signs a transaction with keyPair, the transaction is approved and sent to the blockchain. To resolve the transaction client needs to pass in requestId and signed transaction.

import { Keypair, Transaction } from '@solana/web3.js'

interface SignSolanaTransactionEvent {
requestId: string
transactions: Array<VersionedTransaction>
sessionId: string
}

const alice_keypair = Keypair.generate()

client.on('signTransactions', async (e) => {
const tx = e.transactions[0]
tx.sign([alice_keypair])
// resolve
await client.resolveSignTransaction({
requestId: e.requestId,
signedTransactions: [tx]
})
})