Block height/number undefined in transaction data

I am querying the testnet using fuel-ts sdk using the method getTransactionsByOwner
In the transaction that I see after decoding the raw transaction, the txPointer. block height is undefined. Where can i get the block height from txn data ?

   const res = await provider.operations.getTransactionsByOwner({
              owner: request.address,
              first: fuelPageSize,
            });
            await provider.operations.getBlockWithTransactions
            const transactionsByOwner = res.transactionsByOwner;

            const { edges, pageInfo } = transactionsByOwner;
            const transactions = edges.map((edge) => {
              const { node: gqlTransaction } = edge;
              const { id, rawPayload, status } = gqlTransaction;
            //   console.log("OOOO: ", gqlTransaction);

              const [decodedTransaction] = new TransactionCoder().decode(
                arrayify(rawPayload),
                0
              );
              console.log(
                "decodedTransactions: ",
                decodedTransaction.txPointer?.blockHeight
              );

Hey @singhparshant, can you share what sdk version you’re using? Also, just making sure that you are following the latest updated docs

Hey @singhparshant :wave:

Welcome to the community!

We have the getTransactionsSummaries which seems to fit your use case, it can be used like so:

import { getTransactionsSummaries } from "fuels";

const summaries = await getTransactionsSummaries({
  provider,
  filters: {
    owner: request.address,
  }
});

for (const tx of summaries.transactions) {
  console.log(tx.blockId);
  console.log(tx.transaction.txPointer?.blockHeight)
}

It’s worth noting, that only transactions that have been accepted and processed by the node (with a type of SuccessStatus or FailureStatus) will have the appropriate block information. So, transactions pending execution (with a type of SubmittedStatus) will not contain any block information.

1 Like

I am using 0.82.0 as the latest 0.88 isn’t compatible with beta-5 network yet ?

Yes, beyond 0.82.0 beta-5 network is not supported and the latest ^0.88.0 supports testnet network

What is the graphql url for testnet network that works with the 0.88 ? I didn’t find it in the docs.

You can find it here

Thanks a lot for quick responses. I will try these now.

1 Like

I am trying to query the testnet with the address for which i see some transactions on explorer (Is this the correct testnet explorer link ?): Fuel Explorer

However, when i query with this address, i see an empty array for transactions in the transactions summary results @p.s . Is it the correct explorer link for testnet ?

Also, is there any endpoint which filters transactions based on block numbers ? (provides transactions for an address after a certain block number)

    const provider = await Provider.create(
      "https://testnet.fuel.network/v1/graphql"
    );
            const res = await getTransactionsSummaries({
              provider,
              filters: {
                owner: request.address,
                first: fuelPageSize,
              },
            });
            console.log("Ressss: ", res);

            const transactionsByOwner = res.transactions;
            console.log("Transactions: ", transactionsByOwner);

No, the link for the testnet explorer is this

1 Like

Thanks @p.s for your response. For the code you suggested above, only returns the block ID (tx.blockId) and not the block number. Apparently i have to make another query to get the block height in number ?

const block = await provider.getBlock(
                txn.blockId ? txn.blockId : ""
              );
              const bn = new BN(blockHeight?.height, 16); // Convert hex to decimal
              const heightInt = parseInt(bn.toString());

If I have 100 transactions, I would have to query 100 times. Is there any better way to get the block height ?

Hey @singhparshant,

Updated my answer above.

You can extract the block height via the transaction pointer:

tx.transaction.txPointer?.blockHeight

The block height in txpointer is always undefined even for success status

Could you share the account address you’re using for testing please?

I am using 0xbff2343fc5f189ed4f4531e857e10f216eab3f04435f4e1640a59faad9416957
on beta-5.
Also, is the data on https://app.fuel.network/ synced beta-5 network ?

So in the above example you’ve used the testnet URL.

  • The beta-5 URL is:
    https://beta-5.fuel.network/graphql

  • Yes, https://app.fuel.network/ is currently on the beta-5 network.

Yes, I changed to beta-5 now for testing because i couldn’t find many txns on testnet

This is my code and the result that i see for the address on beta-5 that i mentioned above:

            const transactions = res.transactions;
            const validTransactions = [];

            for (const txn of transactions) {
              if (txn.isStatusSuccess) {
                const { rawPayload } = txn.gqlTransaction;
                //   console.log("OOOO: ", gqlTransaction);

                const [decodedTransaction] = new TransactionCoder().decode(
                  arrayify(rawPayload),
                  0
                );
                console.log(
                  "decodedTransactions height: ",
                  decodedTransaction.txPointer?.blockHeight
                );
              }

Result:

decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
decodedTransactions height:  undefined
......

Update on this, it has been upgraded to testnet and is no longer pointing to beta-5

cc: @singhparshant

1 Like

Potentially your best bet might be to query the GraphQL API, you can try it with the playground and we have docs for it’s usage.

The following query should provide the information that you require:

query TransactionsByOwner {
  transactionsByOwner(owner: "0xbff2343fc5f189ed4f4531e857e10f216eab3f04435f4e1640a59faad9416957", first: 5) {
    nodes {
      status {
        __typename
        ... on SuccessStatus {
          block {
            header {
              height
            }
          }
        }
      }
    }
  }
}
1 Like