# How to use typescript sdk to scan the log corresponding to the contract on the chain

**URL:** <https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936>\
**Category:** TypeScript SDK\
**Created:** [June 20, 2024, 3:56am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936 "2024-06-20T03:56:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 20, 2024, 3:56am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/1 "2024-06-20T03:56:05Z")

</div>

I searched the official documents and found no relevant description. How can I scan the log data emitted in my contract so that it can be put into a centralized database for addition, deletion, modification, and review and provide external services?

---

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 20, 2024, 1:37pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/2 "2024-06-20T13:37:12Z")

</div>

Let me write a simple requirement example

```auto
#[payable]
    #[storage(read, write)]
    fn buy(_str: str){
      .....
     log(BuyEvent {
            time: timestamp(),
            price: market.unwrap().price,
            strings: String::from_ascii_str(_str),
            seller: market.unwrap().owner,
            buyer: msg_sender().unwrap(),
        });
    ........
}

```

If I want to query all BuyEvent events data generated by this contract, how should I do it?

---

<div class="post-metadata">

**Author:** ![crypt0mate](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/crypt0mate/32/2445_2.png) [@crypt0mate](https://forum.fuel.network/u/crypt0mate)\
**Post date:** [June 21, 2024, 1:30pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/3 "2024-06-21T13:30:58Z")

</div>

Hi

Basically the `BuyEvent` will be part of the transaction response so you might also get it each time the contract is called.

[Fuel TS SDK | Fuel Docs](https://docs.fuel.network/docs/fuels-ts/transactions/transaction-response/)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/7/7a3340f0a2b6ac4deed02d01f2b2c65f2532d68f.png)

In Typescript you can do this:  
[Fuel TS SDK | Fuel Docs](https://docs.fuel.network/docs/fuels-ts/contracts/logs/)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/e/e5ed536de5e69ec279795c59fd7e954efbc8f6bb.png)

To read the entire block chain for a specific contracts logs will be something to do via an indexer take a look here:  
[How to Index Data on the Fuel Network using Envio (SwayFarm example) - General - Fuel Network & Sway Language](https://forum.fuel.network/t/how-to-index-data-on-the-fuel-network-using-envio-swayfarm-example/5742)

---

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 21, 2024, 2:04pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/4 "2024-06-21T14:04:47Z")

</div>

@crypt0mate Does it not support SDK to directly scan event data on the chain? I have developed solidity contracts, move contracts, cairo contracts, etc., and their corresponding blockchains all support SDK scanning event data on the blockchain. When it comes to the fuel blockchain, do I need to use a third-party indexer?

---

<div class="post-metadata">

**Author:** ![crypt0mate](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/crypt0mate/32/2445_2.png) [@crypt0mate](https://forum.fuel.network/u/crypt0mate)\
**Post date:** [June 21, 2024, 3:03pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/5 "2024-06-21T15:03:53Z")

</div>

@naz3eh would you know how best to go about this ? is there a GraphQL query of some sort or does this need the fuel-indexer ?

[FuelLabs/fuel-indexer at 5958f20489c3d222b54ae620aa1f43af8982c90f (github.com)](https://github.com/FuelLabs/fuel-indexer/tree/5958f20489c3d222b54ae620aa1f43af8982c90f)

---

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 22, 2024, 10:50am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/6 "2024-06-22T10:50:34Z")

</div>

hello @crypt0mate I try to using GraphQL, However, there is no description related to querying logs data. There are only queries for account balances, transactions, blocks and other information. I can find logs data through some third-party indexes, but currently I don’t know how to parse the obtained data.  
I got the data like this:

```auto
logs: [{"blockHeight":3149211,"txId":"0xa8a9a86402dc5dd75218bf5613bf42a7984f2940369d636be7af819d0931f590","receiptIndex":13,"receiptType":6,"rootContractId":"0x090b1a27ed1f7b353efebaca6a9b46319a1d8bdb7cc2916770bbefd905ae38c1","ra":0,"rb":5566286078492628000,"pc":28492,"is":11688,"ptr":67106273,"len":75,"digest":"0x7381dbff9421b7f9e26d4035aa0d55ea52d60a31debd018e381c271676896d77","data":"0x4000000066769093400000006857c413000000000000000b6d796e616d652e7377617900000000000000003e15247411a05edc60391d7410eabc3d0ee2eb5f8b2bd8102b41e7e94b22fbf2"}]

```

How do I parse the obtained data into the readable data I need?

---

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 27, 2024, 3:18am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/7 "2024-06-27T03:18:04Z")

</div>

Unfortunately, I was not able to solve this problem. What I want is to scan the log data corresponding to my contract on the chain and parse it. I plan to use hyperindex. It is said that it can scan the log data on the chain and parse it normally, but I still hope that the official can improve this function.

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [June 27, 2024, 11:28am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/8 "2024-06-27T11:28:10Z")

</div>

Hey @william, I will be getting in touch with the envio team and will help you get unblocked. Truly appreciate your patience 🙂

---

<div class="post-metadata">

**Author:** ![JasoonS](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/jasoons/32/2727_2.png) [@JasoonS](https://forum.fuel.network/u/JasoonS)\
**Post date:** [June 27, 2024, 12:12pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/9 "2024-06-27T12:12:09Z")

</div>

Hi @william - sorry to see you’re still having difficulties with indexing.

Were you able to set and save the data into the postgres db using the `set` method? [for those reading we have another chat in our discord also].

Please don’t hesitate to reachout to me or our team if you have any difficulties.

---

<div class="post-metadata">

**Author:** ![william](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/william/32/3432_2.png) [@william](https://forum.fuel.network/u/william)\
**Post date:** [June 28, 2024, 12:07am UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/10 "2024-06-28T00:07:23Z")

</div>

Thank you, using hyperindex I have been able to set the log data to the database, and the business logic has been successfully processed and successfully put into the database. I am currently studying how to provide external interfaces to facilitate my front-end page to read data.

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [July 1, 2024, 4:56pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/11 "2024-07-01T16:56:09Z")

</div>

The solution to this issue was resolved [here](https://forum.fuel.network/t/how-to-handle-transactionresultreceipt-in-getdecodedlogs/5997/10)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [July 22, 2024, 12:56pm UTC](https://forum.fuel.network/t/how-to-use-typescript-sdk-to-scan-the-log-corresponding-to-the-contract-on-the-chain/5936/12 "2024-07-22T12:56:48Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
