Skip to content

Type error while calling sendAndConfirmTransaction in solana/web3.js-2.0/basics/transferSol.ts #247

@Mano-08

Description

@Mano-08

Summary

I am facing a TypeScript error when passing the signedTransaction to sendAndConfirmTransaction at solana/web3.js-2.0/basics/transferSol.ts#L91

Image

Error description :

Argument of type 'FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithLifetime' is not assignable to parameter of type 'FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & Omit<...> & { ...; }'.
  Type 'FullySignedTransaction & TransactionWithinSizeLimit & Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }> & TransactionWithLifetime' is not assignable to type '{ lifetimeConstraint: Omit<TransactionBlockhashLifetime, "blockhash">; }'.
    Types of property 'lifetimeConstraint' are incompatible.
      Type 'TransactionBlockhashLifetime | TransactionDurableNonceLifetime' is not assignable to type 'Omit<TransactionBlockhashLifetime, "blockhash">'.
        Property 'lastValidBlockHeight' is missing in type 'TransactionDurableNonceLifetime' but required in type 'Omit<TransactionBlockhashLifetime, "blockhash">'.ts(2345)
lifetime.d.ts(25, 5): 'lastValidBlockHeight' is declared here.

Looks likesendAndConfirmTransaction expects a transaction that is using a recent blockhash, but the transaction we’re passing in could be either a recent blockhash transaction or a durable nonce transaction.

Note

  • Recent blockhash transactions have lastValidBlockHeight
  • But durable nonce transactions do not

Proposed Solution

We require an assertion before calling sendAndConfirmTransaction, to make sure that the signed transaction has the lastValidBlockHeight

assertIsTransactionWithBlockhashLifetime(signedTransaction);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions