assertIsSendableTransaction

function assertIsSendableTransaction<TTransaction>(
    transaction,
): asserts transaction is FullySignedTransaction &
    TransactionWithinSizeLimit &
    TTransaction;

Asserts that a given transaction has all the required conditions to be sent to the network.

From time to time you might acquire a Transaction from an untrusted network API or user input and you are not sure that it has all the required conditions to be sent to the network — such as being fully signed and within the size limit. This function can be used to assert that such a transaction is in fact sendable.

Type Parameters

Type Parameter
TTransaction extends Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }>

Parameters

ParameterType
transactionTTransaction

Returns

asserts transaction is FullySignedTransaction & TransactionWithinSizeLimit & TTransaction

Example

import { assertIsSendableTransaction } from '@solana/transactions';
 
const transaction = getTransactionDecoder().decode(transactionBytes);
try {
    // If this type assertion function doesn't throw, then Typescript will upcast `transaction`
    // to `SendableTransaction`.
    assertIsSendableTransaction(transaction);
    // At this point we know that the transaction can be sent to the network.
    await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });
} catch(e) {
    if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING)) {
        setError(`Missing signatures for ${e.context.addresses.join(', ')}`);
    } else if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT)) {
        setError(`Transaction exceeds size limit of ${e.context.transactionSizeLimit} bytes`);
    }
    throw;
}

On this page