<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ChainCrunch Labs on Medium]]></title>
        <description><![CDATA[Stories by ChainCrunch Labs on Medium]]></description>
        <link>https://medium.com/@chaincrunchlabs?source=rss-84cd3981b8c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dOnep8I5Ya_eCTJy</url>
            <title>Stories by ChainCrunch Labs on Medium</title>
            <link>https://medium.com/@chaincrunchlabs?source=rss-84cd3981b8c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 13:46:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chaincrunchlabs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[On building super fast dApps on Solana]]></title>
            <link>https://chaincrunchlabs.medium.com/on-building-super-fast-dapps-on-solana-68d3ee4f3112?source=rss-84cd3981b8c------2</link>
            <guid isPermaLink="false">https://medium.com/p/68d3ee4f3112</guid>
            <category><![CDATA[solanas]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[rpc]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[ChainCrunch Labs]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 18:20:26 GMT</pubDate>
            <atom:updated>2022-04-25T18:23:49.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*YOIQtfgKs4J4u6tvgYwLTQ.jpeg" /></figure><p>One of the main goals of Solana blockchain is to bring Web2 speed into the blockchain space. This has become possible thanks to multiple innovations in the architecture of the network validators and how the consensus mechanism works. But that’s not the end. dApp developers also need to make sure they are using the right APIs and data access patterns for providing a smooth experience to their users. In this article, we will share a few problems that we have encountered so far and how we managed to solve them. We assume you have some knowledge of Solana programming and how the RPC calls work.</p><p>But first, a little about what we have done so far:</p><p>We built ChainCrunch, an analytics platform where we store, parse, and query all the transactions on Solana.</p><p>We built <em>the index</em>, a prototype for a new generation of Solana RPC and APIs covering real-time and historical queries at superfast speed.</p><p>We built CoralCube, an NFT aggregator and marketplace, using Metaplex open-source auction house program and our own indexing infra to reach unprecedented speed.</p><p>This might sound like three very different projects, but there is a lot of overlap in the tech that we had to develop. We have collaborated with various projects along the way and analyzed their main issues. Here are some of the most common issues we see and how you might be able to solve them.</p><h3>Issue #1: Too many RPC calls</h3><p>If your user interface is showing various information from multiple sources you might end up making tons of requests to the RPC provider. This will definitely slow down your dApp. Fortunately, this is an easy issue to solve.</p><h3>Solution: Batch your RPC requests</h3><p>If you are trying to get multiple accounts data, there is a <a href="https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts">getMultipleAccounts</a> RPC method that you can use to fetch all of the data with a single request. This can be used for up to 100 accounts in each request.</p><p>But there is a better, more general approach for batching requests which works for all sorts of RPC calls and is not limited to fetching account data. This is not very well documented in the Solana docs and there is no convenience function for it in the javascript web3 library, but we really recommend you implement and use it. There is a single line in the API documentation that states:</p><blockquote><em>Requests can be sent in batches by sending an array of JSON-RPC request objects as the data for a single POST.</em></blockquote><p>This means you can batch all your requests using the JSON-RPC batching protocol!</p><p>Here is a single curl request getting the current slot, the current balance of a single account, and the data for two other accounts all in one request:</p><pre>curl https://rpc.theindex.io -X POST -H &quot;Content-Type: application/json&quot; -d &#39;<br>  [<br>      {&quot;jsonrpc&quot;:&quot;2.0&quot;, &quot;id&quot;:1, &quot;method&quot;:&quot;getSlot&quot;},<br>      {&quot;jsonrpc&quot;:&quot;2.0&quot;, &quot;id&quot;:2, &quot;method&quot;:&quot;getBalance&quot;, &quot;params&quot;:[&quot;BsvtXMu1eGKrAhpP636EnNG8LWddxqmCDq8zcEG8CwY3&quot;]},<br>      {<br>        &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>        &quot;id&quot;: 3,<br>        &quot;method&quot;: &quot;getMultipleAccounts&quot;,<br>        &quot;params&quot;: [<br>        [<br>            &quot;vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg&quot;,<br>            &quot;4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA&quot;<br>        ]<br>        ]<br>      }<br>  ]<br>&#39;</pre><h3>Issue #2: Slow RPC calls</h3><p>Some of the Solana RPC methods like getAccountInfo or even getMultipleAccounts are relatively cheap compared to other methods like getTransaction or getProgramAccounts</p><p>Of course, this is connected to how each of these APIs are implemented and what’s happening on the backend for fulfilling these requests. There is no easy solution for this issue on the client side. That’s why we built the index and solved it on the server side! Here is a little summary of what can be improved on the server side:</p><h3>Indexing Historical Transactions:</h3><p>If you want to show an activity history of what the users did in your dApp, you need to fetch their historical transactions. Since there is no filtering mechanism in the RPC method, you may fetch transactions that are irrelevant to your dApp like token transfers that you have to hide in the front-end. This adds a lot of complexity to your UI code in terms of filtering them out, pagination, etc. Another way to solve this issue is to create a backend service that indexes all your program transactions and exposes custom APIs that your user interface can use, this needs backend development, server maintenance, monitoring, etc. A third solution that we are working on is to provide APIs for fetching user transactions with a certain program mentioned in the transaction accounts. Stay tuned!</p><h3>getProgramAccounts:</h3><p>This is a tough one! By using <a href="https://solanacookbook.com/core-concepts/pdas.html#facts">PDAs</a> you can limit your need for using getProgramAccounts but it will not eliminate it completely. Our solution for this problem is using the Solana geyser plugins. We’ve been using this architecture for a few months and we believe it has a lot of potential. Using this plugin you can extract all the accounts you need for your dApp and index them according to your access patterns. This will definitely make your dApp faster but also needs a lot of investment, you have to maintain Solana validators, the plugins, etc. That’s why <a href="https://chaincrunchlabs.medium.com/getprogramaccounts-is-dead-long-live-the-getprogramaccounts-7bfb2c16e459">we are providing</a> faster getProgramAccounts out of the box on <em>the index</em>. We can create custom indexes on the fly and speed up the calls by orders of magnitude.</p><h3>Issue #3: Latency in propagating changes</h3><p>While building CoralCube we faced a trade-off between the consistency of data and the smoothness of UX. We had to make sure that our users’ transactions are finalized in order to have a consistent state of our database, on the other hand, we didn’t want our users to wait for ~30 seconds to see their listings on the website. This is a general problem for dApps that rely on custom data indexing, especially if you update your database based on the most recent transactions. If they use the data that is not finalized yet, they might end up with an inconsistent state and the need for reverting the state but using finalized data introduces a long lag. When you are using the RPC calls for fetching information, all of this is handled automatically, if the user transactions don’t get confirmed the state is automatically reverted by the validator and a page refresh will fix the issue but you have to handle it manually if you have your own indexing solution.</p><h3>Solution: Trust, but verify</h3><p>The main solution here is to apply the changes temporarily and revert them if they are not finalized in the blockchain. This is very similar to how Solana validators are working as well, they can keep multiple forks active, but in the end, only one will be used as the finalized version and the others will be ignored.</p><p>This can be done by subscribing to your program via WebSockets or the Geyser plugin to listen for the most recent changes and apply them, but don’t forget to revert if needed. Of course, this is a lot of extra work to do but we believe it is necessary to bring the next billion Web2 users to Solana!</p><h3>Conclusion</h3><p>Building slick dApp interfaces come with its own set of challenges and it’s not straightforward to create the same web2 experience with a blockchain as the backend, but we believe Solana architecture provides enough tooling and flexibility to make it possible.</p><p>We are still early and there is a lot of glass chewing left to be done! #solanaspeed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68d3ee4f3112" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[getProgramAccounts is dead, long live the getProgramAccounts!]]></title>
            <link>https://chaincrunchlabs.medium.com/getprogramaccounts-is-dead-long-live-the-getprogramaccounts-7bfb2c16e459?source=rss-84cd3981b8c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bfb2c16e459</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[rpc]]></category>
            <category><![CDATA[solanas]]></category>
            <dc:creator><![CDATA[ChainCrunch Labs]]></dc:creator>
            <pubDate>Fri, 08 Apr 2022 15:46:04 GMT</pubDate>
            <atom:updated>2022-04-08T15:46:04.163Z</atom:updated>
            <content:encoded><![CDATA[<p>There have been a lot of discussions recently about getProgramAccounts, why it’s “toxic”, and what the developers should do about it. In this article, we will go deep into the issue, how it should be fixed, and how the index can help.</p><h3>What is getProgramAccounts and why do we need it?</h3><p>Solana RPC provides multiple methods to fetch the current state of the network. These methods are the building blocks of creating a dApp on Solana. Some of them are very simple like getAccountInfo which fetches the data for a single account, while some of them are more complex like the getProgramAccounts. In summary, the getProgramAccounts method fetches a subset of accounts owned by a specific program based on some filtering criteria. Ok, that was very technical! Let’s explain using a simple example. The Token standard on Solana defines a straightforward mechanism to create new tokens (like DevCoin!) and send them to different wallets. Of course, this information needs to be stored in the accounts. The program responsible for managing this information is the <a href="https://spl.solana.com/token">Token program</a> and this is the actual structure for it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGwsGF4lK9dR2bwxmV-CzA.png" /><figcaption>Structure of token accounts in Solana</figcaption></figure><p>For example, if you have 10 USDC on Solana, you have a token account with the following information:</p><ul><li>Mint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v (<a href="https://solscan.io/token/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v">USDC Mint</a>)</li><li>Owner: Your wallet address</li><li>Amount: 10.000000 (For USDC mint amount is stored with 6 digits of decimal for more precision)</li><li>… and the rest of the fields</li></ul><p>So far, there are more than 107 million of these accounts on Solana! That is more than 17 GB on the blockchain! Now let’s say you want to find all the token accounts which belong to you. You have to look for all the accounts that store your wallet address in the Owner field and that is exactly what you ask in the RPC request! Here is an example:</p><pre>  {<br>    &quot;method&quot;: &quot;getProgramAccounts&quot;,<br>    &quot;params&quot;: [<br>      &quot;TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA&quot;,<br>      {<br>        &quot;encoding&quot;: &quot;jsonParsed&quot;,<br>        &quot;filters&quot;: [<br>          {<br>            &quot;dataSize&quot;: 165<br>          },<br>          {<br>            &quot;memcmp&quot;: {<br>              &quot;offset&quot;: 32,<br>              &quot;bytes&quot;: &quot;vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg&quot;<br>            }<br>          }<br>        ]<br>      }<br>    ]<br>  }</pre><p>In the beginning, we said that getProgramAccounts method fetches a subset of accounts owned by a specific program based on some filtering criteria. Let’s find this information in our RPC request. Here we want to search for accounts that are managed by the TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA program (Solana Token standard program) and we have two filtering criteria:</p><ul><li>The size of the account should be 165, which is the size of token accounts. There are other accounts with different sizes for storing different kinds of information which we don’t need here.</li><li>We only need the accounts with a specific address stored in offset 32 (start of the Owner field). This is accomplished by the memcmp (short for <a href="https://www.cplusplus.com/reference/cstring/memcmp/">memory compare</a>) filter.</li></ul><p>That’s it! That’s how you can get all your token accounts in Solana. Now suppose you want to find all of the token accounts for a specific mint. All you have to do is to change the filtering criteria:</p><pre>{<br>    &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>    &quot;id&quot;: 1,<br>    &quot;method&quot;: &quot;getProgramAccounts&quot;,<br>    &quot;params&quot;: [<br>      &quot;TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA&quot;,<br>      {<br>        &quot;encoding&quot;: &quot;jsonParsed&quot;,<br>        &quot;filters&quot;: [<br>          {<br>            &quot;dataSize&quot;: 165<br>          },<br>          {<br>            &quot;memcmp&quot;: {<br>              &quot;offset&quot;: 0,<br>              &quot;bytes&quot;: &quot;TESTpKgj42ya3st2SQTKiANjTBmncQSCqLAZGcSPLGM&quot;<br>            }<br>          }<br>        ]<br>      }<br>    ]<br>}</pre><p>As you can see, the getProgramAccounts is a very versatile method that can help us access information in an efficient manner.</p><h3>Why is it slow?</h3><p>It’s not slow! It’s as fast as it can be! The RPC servers don’t know about the programs that are being deployed and their GPA access patterns. So, the best it can do is to check each account and see if the filtering criteria are accepted or not. The complexity of this procedure is linear in terms of how many accounts should be scanned. For some specific and popular access patterns like the one mentioned above, RPC servers have some configurations which enable faster retrieval by maintaining an extra indexing layer on top of the raw accounts data, but that is the exception (with a lot of extra memory usage and processing power requirements), not the rule. Now if your program has a few thousand accounts, you won’t notice anything cause it’s just super fast. But for programs like Metaplex Metadata which has 60+ million accounts, all hell will break loose. That’s the main reason that this procedure call is heavy and notorious for RPC providers!</p><h3>What you can do?</h3><p>The replacement for this is the <a href="https://docs.solana.com/developing/plugins/geyser-plugins">Geyser plugins</a>. Basically, a geyser plugin can listen to all the account changes and store what is relevant for your deployed programs. For example, a plugin that stores and indexes the accounts into a PostgreSQL database. Then you should also write an API that provides this data to your dApp frontend.</p><p>Here is a short summary of what you have to do:</p><ul><li>Rent a beefy server to run a validator on top of it (the cheapest servers are around $300/month, a decent one around $1k/month)</li><li>Learn how to <a href="https://docs.solana.com/running-validator">run a validator</a>, how to tune your server, how to monitor it, etc.</li><li>Write a Geyser plugin in Rust, and attach it to your validator</li><li>Write an API service that exposes the data to your dApp again</li><li>Maintain all the extra burden as your app grows</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*jwOuwWwj-2UWA63a.gif" /><figcaption>Devs after finding out the getProgramAccounts is super slow and all the extra work!</figcaption></figure><p>But this is toooo much extra work to do. It can easily delay your product launch for a month or two and you may need to hire DevOps and backend developers. That’s when the index can help!</p><h3>A Better alternative</h3><p>We were building on top of the Geyser plugin for 6+ months now. We saw the issues of getProgramAccounts from day one and we did a lot of glass chewing to fix them!</p><figure><img alt="The first message a Solana co-founder sent us!" src="https://cdn-images-1.medium.com/max/429/1*3-M6ri5hFGWPzqO-e4eseQ.png" /><figcaption>The first message the Solana co-founder sent us! Way before the plugin was renamed to Geyser!</figcaption></figure><p>The index&#39;s mission is to help developers in building cool dApps without worrying about the infrastructure. As a first step, we are providing a hyper-fast getProgramAccounts RPC. We did all the stuff we mentioned so you don’t have to do it. We created a scalable system, in which we can add arbitrary indexes for faster fetching on getProgramAccounts. Currently, we support multiple scenarios (fetching staking accounts, NFT collection hashlists,...) and we are expanding our indices continuously. One of the most popular use cases of getProgramAccounts at the moment is to find an NFT collection based on their creators. On a normal RPC service this would take about a minute but on our nodes, this would take less than 5 seconds! Check out <a href="https://theindex.io/">theindex.io</a> for more information. #solanaspeed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bfb2c16e459" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>