TechnologySeptember 26, 2022

Blockchain (Data) without the Pain

Eric Hallow
Eric HallowOnboarding Engineer
Blockchain (Data) without the Pain

This post is about harnessing the power of reliable blockchain data with real time query capability. We can index blockchain data directly from Ethereum nodes into Astra DB, resulting in a tougher backend code. Instead, we use the power of Astra DB’s Ethereum Blockchain dataset in combination with Stargate API to make things simpler. Here, we use this data to build an application providing a real-time feed of every new NFT minted.

There are two guarantees in the crypto markets: massive volatility and the development of cutting-edge applications. Through bear markets and bull markets, developers continue building new, innovative solutions to problems in Web3. What’s consistent through all of these applications is the need for reliable blockchain data with the real-time query capability. The Ethereum dataset of DataStax Astra DB provides a dependable source for all your data needs. In this article, I will show you application examples, building pain points, and how to get started with the dataset. 

Building Applications

Crypto Wallets, Non-Fungible Token (NFT) marketplaces or Blockchain Explorers are just a few examples of applications utilizing blockchain data. There are endless opportunities to build applications after solving infrastructure problems. We have simplified that entire backend process by allowing developers to utilize APIs they are already familiar with.

We leveraged this to build a real-time feed of every new NFT mined. This wouldn’t have been possible without Astra DB. The blockchain data is indexed directly from Ethereum Nodes into Astra DB after a new block is mined. This application makes API requests directly to Astra DB. No need to worry about nodes or remote procedure calls (RPC). 

Astra-powered real-time NFT feed
Figure 1: Astra-powered real-time NFT feed

The Pain of Building in Web3

If you want to develop a product built on Blockchain data, a wide variety of problems stand in your way. A lot of the data out there is not available in real time and is expensive. Blockchains are decentralized and immutable, but require a great deal of expertise to navigate. Most developers want to skip ahead of those problems and insert data into the frontend of their applications with simple API calls.

Difficulty Running Ethereum Nodes

Running your own Ethereum node / IPFS node adds a layer of complexity onto your application. By no means is it impossible, but the lack of quality documentation makes a workflow slow and painful. You will spend more time troubleshooting your node than developing the greater application. As the saying goes, “There is no customer support in Web3.” You will feel that pain as you “trial-and-error” your way through every problem you are trying to solve. 

More RPC Calls and Costs

In order to pull all the necessary JSON data for any NFT, you will need to make a variety of different RPC calls. This makes your backend code 10x tougher to manage. After evaluating a few of the infrastructure options, the complexity keeps growing and we haven’t even mentioned the additional costs. You can build this way, but there are simple, cheaper options to get your data. 

The Astra DB Ethereum Blockchain dataset meets developers where they are now. With just a simple API call, you can pull all the necessary metadata equal to those 10+ RPC calls. Check out this GET request to the Ethereum Dataset below. Quick and easy. As a developer, this will be second nature to you.

curl --request GET \
    --url https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/rest/v2/keyspaces/${ASTRA_DB_KEYSPACE}/ETH/${ASTRA_ORG_ID}\
    --header "x-cassandra-token: ${ASTRA_DB_APPLICATION_TOKEN}"

Building with Ethereum Data

Astra DB has indexed the entire Ethereum blockchain. You can leverage speed, performance, and scalability directly into your application data. This will lower your barriers to entry and allow you to focus on building your product on top of a reliable source. Within just minutes, you can spin up a database with our NFT dataset and run queries. 

Create Astra DB

Creating an Astra database
Figure 2: Creating an Astra database

Load Ethereum Dataset in Astra DB

Create an entire database with all Ethereum data in your newly created database.

Creating a database with Ethereum data
Figure 3: Creating a database with Ethereum data

CQL Query

Navigate to the CQL console in Astra. Explore the NFT dataset by running some simple CQL queries.

Running a CQL query on the NFT datasetFigure 4: Running a CQL query on the NFT dataset.

Turn on expand output and run this simple query to view the NFT data.

token@cqlsh> expand on;
Now Expanded output is enabled
token@cqlsh:eth_v2> select * from nfts limit 5;

The output will show all the necessary data associated with the NFTs.

 contract_address | 0x05ba660296914719f089a36f933752fdb0d1ba16
token_id         | 166
block_number     | 14951160
metadata         | {"name":"CyberModern Chapter 2 #166","description":"","image":"ipfs://QmZ6FqRfDs5L2kC4jyzZ1GpzsAsb3kDAEnNe5AbAqvZwhz/166.png","edition":166,"attributes":[{"trait_type":"Style","value":"Chimerism"},{"trait_type":"Palette","value":"Dark"},{"trait_type":"Mood","value":"Excited"},{"trait_type":"Scent","value":"Black pepper"},{"trait_type":"Scent","value":"Formalin"},{"trait_type":"Scent","value":"Rain"},{"trait_type":"Subject","value":"Beast"},{"trait_type":"Subject","value":"Pseudo-living"},{"trait_type":"Subject","value":"Supenatural phenomena"},{"trait_type":"Gallery","value":"Galerie Abercrombie"}]}
name             | CyberModern
owner_of         | 0x0000000000000000000000000000000000000000000000000000000000000000
symbol           | CYBERM
token_standard   | ERC721
token_uri        | ipfs://QmUAbYu56oeyADm98HtkmpuZG1yjswf1bmG713yqBFMdET/166.json

Connect your Application

You can integrate all this data into your application using our Stargate APIs. Follow these simple steps in the connect tab to use your API of choice. With a few lines of code, you can pull all the NFT data into your application.

Steps to pull NFT data into your application
Figure 5: Steps to pull NFT data into your application.

Conclusion

By following these steps, you have successfully connected and queried blockchain data indexed on Astra. You can leverage scaling, high availability, and Stargate APIs to continue growing your project. Need help? Experienced developers staff the chat console in Astra DB to ensure your success with Ethereum data on Astra DB. Start building and we will help you along the way! 

Subscribe to the DataStax Tech Blog for more developer stories. Check out our YouTube channel for free tutorials and follow DataStax Developers on Twitter for the latest news in our developer community.

Resources

  1. DataStax Astra DB
  2. DataStax APIs: Stargate
  3. DataStax Web3: Real-time NFT feed
Discover more
DataStax Astra DB
Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.