# Guidelines for Indexing SUI Blockchain Data **Published by:** [Chainbase](https://paragraph.com/@chainbase-2/) **Published on:** 2023-07-17 **URL:** https://paragraph.com/@chainbase-2/guidelines-for-indexing-sui-blockchain-data ## Content The Author: masterdaiIntroductionIndexing is an essential tool in the blockchain ecosystem, streamlining the organization and retrieval of data. It bolsters efficiency, enhances user experience, simplifies data analysis, and ensures scalability. By facilitating rapid data access, it supports real-time applications and optimizes interactions, a feature that is particularly crucial for platforms like DeFi. Indexing also aids in various tasks, from detecting fraudulent activity to understanding user behavior. As the volume of blockchain data grows, indexing ensures that application performance remains high. As the only data cloud indexing provider in the Sui blockchain ecosystem, Chainbase plays a critical role in enabling efficient data retrieval. In the upcoming guide, I will illustrate how developers can effectively access on-chain data using several SQL examples. This will offer a hands-on understanding of how to utilize Chainbase's indexing capabilities to improve data interaction and analysis within the Sui blockchain.About SUISui is a groundbreaking smart contract platform that revolutionizes the traditional blockchain model by centering storage around objects, which are programmable entities managed by smart contracts. Unlike the conventional account-based storage model where each account contains a key-value store, Sui's approach focuses on objects as the fundamental unit of data storage. These objects are digital entities that store data directly on the blockchain. Developers can define, create, and manage these objects, which represent user-level assets. Each object possesses distinct attributes, including ownership, and these attributes can be updated based on the governing logic of the smart contract that created the object. This object-centric data model of Sui allows digital assets and their attributes to exist on-chain and independently of smart contracts. This innovative approach offers a new level of flexibility and functionality in the blockchain space, enabling more complex and dynamic interactions with digital assets.PrerequisitesA free account at Chainbase with an API key.An IDE. Our examples are shown in JavaScript, you can use VS Code as your IDE for example.Register and Get API KeyTo begin with, you'll need to register on Chainbase and obtain an API key. This key will be used to authenticate your requests to the Chainbase API.SQL ExampleLog in to your Chainbase dashboard. Execute the following SQL query to retrieve the required data:Query 1: Finding the Most Active AddressWant to identify the most transaction-heavy address in your blockchain? The following SQL query can help:SELECT sender, count() as total FROM sui.transactions GROUP BY sender ORDER BY total DESC Query 2: Most Utilized Module and Event TypeTo identify the most commonly used module and event type, use the query below:SELECT module, event_type, COUNT(*) AS total FROM sui.events GROUP BY event_type, module ORDER BY total DESC; Query 3: Filtered Data ExtractionLooking for specific transaction content? Filter your search using this SQL query:select * from sui.transactions where transaction_content like "%fuddies%%orderbook%" order by id DESC limit 100 Query 4: Fetching Specific Event DataFor retrieving specific event data from the Sui blockchain, execute the following query:SELECT id, module, sender, transaction_digest, event_type FROM sui.events WHERE event_type LIKE "%0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b%" ORDER BY id DESC LIMIT 100 Generating the APIOnce you have the SQL query to retrieve the desired data, the next step involves generating an API request to fetch the real-time Sui blockchain data. Follow the steps below:chainbases-api.pngStep 1: Install Node.js and the Axios library if you haven't already. Step 2: Use the following code snippet to make the API call:const axios = require('axios'); axios.post('https://api.chainbase.online/v1/dw/query', {"query":"SELECT\n id,\n module,\n sender,\n transaction_digest,\n event_type\nFROM\n sui.events\nWHERE\n event_type LIKE \"%0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b%\"\norder by\n id desc\nlimit\n 100"}, { headers: { 'x-api-key': '[api-key]' } }) .then(response => { const data = response.data.data; console.log(data); }) .catch(error => { console.error(error); }); This code snippet utilizes the Axios library to send a POST request to the Chainbase API endpoint (https://api.chainbase.online/v1/dw/query). The SQL query is included in the request payload, and the 'x-api-key' header is used for authentication.Retrieving and Printing Sui Blockchain DataAfter making the API call, you will receive a response containing the real-time Sui onchain data. Follow the steps below to extract and print the data: Access the retrieved data from the response using response.data.data. Display the data by printing it on the console log. Run node 'filename'.js{ event_type: '0xbc3df36be17f27ac98e3c839b2589db8475fa07b20657b08e8891e3aaf5ee5f9::mint_event::MintEvent<0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b::fuddies::Fuddies>', id: '306968', module: 'fuddies', sender: '0x65afcd7679a1570f11b3865d8c0d13e070b4cf7587af11c3eacd98e97b6252a3', transaction_digest: '6GMShTdQyeLzieJBLyVjrJn7nZTeFKEEnhRDTKZd6dqX' }, { event_type: '0xbc3df36be17f27ac98e3c839b2589db8475fa07b20657b08e8891e3aaf5ee5f9::mint_event::MintEvent<0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b::fuddies::Fuddies>', id: '304865', module: 'fuddies', sender: '0x65afcd7679a1570f11b3865d8c0d13e070b4cf7587af11c3eacd98e97b6252a3', transaction_digest: 'FDPsGKnux8gCDcPWbKqkLbg28bnu6A16NUdsQN9LQb5x' }, { event_type: '0xbc3df36be17f27ac98e3c839b2589db8475fa07b20657b08e8891e3aaf5ee5f9::mint_event::MintEvent<0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b::fuddies::Fuddies>', id: '304864', module: 'fuddies', sender: '0x65afcd7679a1570f11b3865d8c0d13e070b4cf7587af11c3eacd98e97b6252a3', transaction_digest: 'FDPsGKnux8gCDcPWbKqkLbg28bnu6A16NUdsQN9LQb5x' }, { event_type: '0xbc3df36be17f27ac98e3c839b2589db8475fa07b20657b08e8891e3aaf5ee5f9::mint_event::MintEvent<0xac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b::fuddies::Fuddies>', id: '304863', module: 'fuddies', sender: '0x65afcd7679a1570f11b3865d8c0d13e070b4cf7587af11c3eacd98e97b6252a3', transaction_digest: 'FDPsGKnux8gCDcPWbKqkLbg28bnu6A16NUdsQN9LQb5x' }, ... Experience Sui's Dashboard with a Front-End Demochainbase-sui-dashboard.11.pngConclusionIn the fast-paced world of blockchain technology, data management can seem daunting. However, with a tool like Chainbase at your disposal, you can easily navigate through the sea of data that blockchain platforms like Sui generate. From generating insightful SQL queries to making API calls, Chainbase empowers developers to make the most of blockchain data.Frequently Asked Questions (FAQs)1. What is Chainbase? Chainbase is a leading data cloud indexing provider in the Sui blockchain ecosystem, enhancing data retrieval processes for developers. 2. What makes Sui different from other blockchain platforms? Sui uses an innovative object-oriented storage model, contrasting the traditional account-based models of other blockchain systems. 3. What do I need to start using Chainbase? You will need a free account at Chainbase and an API key, along with an Integrated Development Environment (IDE) like VS Code. 4. How can I extract specific data from the Sui blockchain? You can utilize SQL queries to extract specific data. We also allows you to generate API requests for real-time data retrieval. 5. How do I authenticate my requests to the Chainbase API? You will use an API key acquired from Chainbase to authenticate all your requests.About ChainbaseChainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort. Want to learn more about Chainbase? Visit our website chainbase.com Sign up for a free account, and Check out our documentation. Website|Blog|Twitter|Discord|Link3 The Original Link: Guidelines for Indexing SUI Blockchain Data ## Publication Information - [Chainbase](https://paragraph.com/@chainbase-2/): Publication homepage - [All Posts](https://paragraph.com/@chainbase-2/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@chainbase-2): Subscribe to updates