0

So in my code I am doing the following in my backend and wondering which I should use?

const sig = await web3.sendAndConfirmTransaction(connection, createMetadataTx, [mint_authority], {
      skipPreflight: false
    })
const sig = await connection.sendTransaction(
      createMetadataTx,
      [mint_authority],
      {
        skipPreflight: false,
      }
    );

I am guessing that the sendAndConfirmTransaction takes a little longer but confirms that the trx has been accepted for processsing, but not necessarily finalized?

And what bearing does my connection 'commitment' have on this?:

const connection = new Connection(tokenType.cluster, "processed");
1977
  • 2,580
  • 6
  • 26
  • 37

1 Answers1

1

sendTransaction just broadcasts the transaction and does not wait for it to confirm on the network. You can then use confirmTransaction separately to check it the transaction was confirmed on the network.

sendAndConfirmTransaction does both and doesn't return until the transaction is either confirmed on the network or dropped.

You would:

  • Use sendTransaction if you are ok with send and forget or manual confirm later
  • Use sendAndConfirmTransaction if you want to know the transaction status before any further processing
Jacob Creech
  • 1,797
  • 2
  • 11