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

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?

Let me write a simple requirement example

#[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?

1 Like

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

In Typescript you can do this:
Fuel TS SDK | Fuel Docs

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

1 Like

@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?

@Nazeeh21 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)

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:

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?

1 Like

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.

1 Like

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

2 Likes

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.

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.

3 Likes

The solution to this issue was resolved here

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