Skip to main content

Signing Transactions

Transaction

Your app is able to request approval to sign and send transactions after it has established a connection to the wallet provider. A popup window is opened when you request approval from a user. The user can either approve or reject the request.

Transaction Requirements

Your Transaction instance should:

  1. Include one or more TransactionInstructions
  2. Be signed by any accounts other than the user (if other signatures are required)
  3. Not exceed 1232 bytes when serialized

Avana will provide a recentBlockhash if it is not set, and Avana will designate the user address as the feePayer if it is not set.

Recent Blockhash Expiration

Solana's time window for a valid recentBlockhash is about two minutes. Be sure that you include a recent finalized blockhash when submitting your transaction.

The provider will automatically append a recentBlockhash to the transaction if it is not already set.

Transaction Simulation

Avana simulates the transaction and shows the results to the user before requesting the user's signature. This helps the user understand the changes to account balances and the programs called as part of the transaction.

The transaction will not be displayed to the user if the simulation fails. In this instance, the wallet provider will throw Error Code -32003, Transaction rejected with the error data attribute containing the reason why the transaction failed (see Errors).

Common reasons transactions fail

  • Recent blockhash has expired
  • Insufficient balance
    • SOL balance does not cover amount required for network fee and/or transaction instructions
    • Token balance does not cover amount required by transaction instructions
  • Not signed by all required accounts (other than the user)
  • Exceeded size limit of 1232 bytes when serialized
  • Network performance or connectivity issues
  • Invalid instructions
  • Invalid accounts specifications (check all accounts have proper settings for isSigner and isWritable)

Provider Methods

signTransaction

Returns a single signed transaction instance. You must submit the transaction to the network.

Parameters:

  • <Transaction> - Transaction instance

Results:

  • <Transaction> - Transaction instance signed by user

signAllTransactions

Returns an array of signed transactions instances. You must submit the transactions to the network.

Parameters:

  • <Transaction[]> - Transaction instance array

Results:

  • <Transaction[]> - Transaction instance array signed by user

signAndSendTransaction

Signs and sends a single transaction. Avana submits the transaction to the network and returns a transaction signature.

Parameters:

  • <Transaction> - Transaction instance
  • SendOptions: <object> - (optional) Configuration object containing SendOptions

Results:

  • <object>
    • signature: <string> - Transaction signature
    • publicKey: <PublicKey> - Public Key of user account

signAndSendAllTransactions

Signs and sends a multiple transaction (limit of 5). Avana submits the transaction to the network and returns transaction signatures.

Parameters:

  • <Transaction[]> - Transaction instance array
  • SendOptions: <object> - (optional) Configuration object containing SendOptions

Results:

  • <object[]> - Array of objects
    • signature: <string> - Transaction signature
    • publicKey: <PublicKey> - Public Key of user account

Send Options

When you request signAndSendTransaction(s), you can specify the following Send Options below.

  • skipConfirmation: (default: false) - Wait for confirmation from the network. If set to false then Avana will submit the transaction(s) to the network and immediately return the signature(s) - the status(es) are unknown.
  • confirmationTimeout: (default: 45) - Amount of time (in seconds) to check the network for a confirmation.
  • confirmationStatus: (default: processed) - Commitment level required for confirmation (processed|confirmed|finalized)

Send Result

When you request signAndSendTransaction(s), the Avana Wallet provider returns a Promise with the result. The promise is rejected if there is an Error (see Errors).

Examples

Send Transaction
const transaction = new Transaction();
// ... build transaction

try {
const signedTransaction = await window.solana.signTransaction(transaction);
} catch (error) {
// User rejected request, or invalid transaction (see Errors)
}
Send Transactions
const transactionOne = new Transaction();
const transactionTwo = new Transaction();
// ... build transactions

try {
const transactions = [transactionOne, transactionTwo];
const signedTransactions = await window.solana.signAllTransactions(transactions);
} catch (error) {
// User rejected request, or invalid transaction (see Errors)
}
Sign And Send Transaction
const transaction = new Transaction();
// ... build transaction

try {
const { signature, publicKey } = await window.solana.signAndSendTransaction(
transaction
);
} catch (error) {
// User rejected request, or invalid transaction (see Errors)
}
Sign And Send Transactions
const transactionOne = new Transaction();
const transactionTwo = new Transaction();
// ... build transactions

try {
const transactions = [transactionOne, transactionTwo];
const txSignatureObjects = await window.solana.signAndSendAllTransactions(
transactions
);
} catch (error) {
// User rejected request, or invalid transaction (see Errors)
}