Guides

Lens Transaction Status

๐Ÿšง

This request is protected by authentication

Normally when you broadcast transactions to the blockchain you wait for the receipt to know the transaction is completed. The transaction is in a pending state until you have a receipt. If you use ethers.js you normally use their method to wait to get the receipt.

await tx.wait();

As this is slightly different your source of truth is actually the API's indexer and database. So this method allows you to swap out the wait method from ethers.js and use this API query as a source of truth for when the transaction is complete.

The indexer tracks all transaction hashes to allow you to easily query to work out if the indexer has now broadcasted it.

Check status of transaction

Request

LensTransactionStatusRequest

  • forTxId: TxId (optional)
    • This is the transaction id returned from broadcasting a transaction.
  • forTxHash :TxHash (optional)
    • The transaction hash of the transaction return from broadcasting a transaction.

Although both forTxId and forTxHash are optional, you must supply at least one.

You may see that the request takes in a nullable forTxHash or a nullable forTxId if you are not using the server relay you should always use the forTxHash when doing this query. Please note if the user upgrades the gas price the txHash changes so your client should handle that on those edge cases to avoid being stuck in a loop until that txHash is dropped (sometimes can take a long time).

๐Ÿ“˜

When Using The Profile Manager

When using the Profile Manager (gasless), you must use the forTxId over the forTxHash as the gasless would bump up the transaction if the gas prices move meaning a new txHash will be generated.

Invocation

const result = await client.transaction.status({ forTxId: TX_ID });

// or wait till status is complete
const result = await lensClient.transaction.waitUntilComplete({
  forTxId: TX_ID,
});
fragment LensTransactionResult on LensTransactionResult {
  status
  txHash
  reason
  extraInfo
}

query LensTransactionStatus($request: LensTransactionStatusRequest!) {
  result: lensTransactionStatus(request: $request) {
    ...LensTransactionResult
  }
}

Response

LensTransactionResult

Full GraphQL API Example

๐ŸŒ

Check Lens Transaction Status: GraphQL API Example