How to Retrieve Transaction ID Before Sending Transaction Without await on a Deployed Fuel Contract?

I am working on a Fuel blockchain project where I need to send transactions to an already deployed contract. My goal is to retrieve the Transaction ID before the transaction is sent, without using await. This is to check the transaction status (success or failure) asynchronously.

I am following the Fuel documentation, but the provided examples focus on deploying new contracts, whereas I am interacting with an existing contract.

for (let i = 0; i < transactionsPerAccount * accounts.length; i++) {
  const accountIndex = i % accounts.length;
  const account = accounts[accountIndex];
  const userWallet = Wallet.fromPrivateKey(account.privateKey, provider);

  try {
    await delay(20); // Simulate delay between transactions
    const contract = new LyncIgnite(contractAddress, userWallet);
   contract.functions.hit("1").call();

    console.log(
      `Transaction ${i + 1} processed successfully by account ${
        userWallet.address
      }. Transaction ID: ${txn.transactionId}`
    );
  } catch (txError) {
    console.error(
      `Error processing transaction for account ${userWallet.address}:`,
      txError
    );

    console.log("Added failed transaction to retry queue.");
  }
}

  • How can I retrieve the Transaction ID immediately before sending the transaction without using await?
  • Is there any method or API available in the Fuel SDK to interact with a deployed contract and get a transaction’s ID synchronously?
  • How can I later verify the success or failure of the transaction once the ID is retrieved?
1 Like

Hi @jitendra-lync, thanks for checking out the SDK!

Firstly, I’d recommend checking out the custom transactions from contract calls documentation, it has a good example of working with an existing contract.

To retrieve a transaction ID, you can use the getTransactionID function available to a transaction request. For a contract call, you’ll need to convert it to a transaction request first. I’d expect this to look like:

const txId = contract.functions
  .hit("1")
  .getTransactionRequest()
  .then((request) => txRequest.getTransactionId(1));

To verify the success or failure of a tx, check out the transaction response. Here you can see all the information for a submitted tx, including it’s status, reciepts, gas etc.