Feed

In Deep With Blockchain Data: Two New PSL Web3 Projects

Insights

1.10.2022
Dave Peck & the PSL Team

In our previous post about the world of crypto we mentioned that, beneath the sound and fury, blockchains are simply a new kind of database. The data they contain tells the story of the collective actions of hundreds of millions of crypto accounts.

Alas: making sense of that story isn’t as straightforward as we’d like. From a developer’s perspective, blockchains aren’t typical easy-to-query databases. Yes, they’re purpose-built to capture and retain history, but asking certain questions about that history — particularly questions that aggregate lots of data — can be hard. For instance, while it’s trivial to directly ask a blockchain for an account’s current balance, it’s much more difficult to ask for an account’s average balance over the past month. It’s easy to ask who “owns” a specific NFT but it’s much more work to get that token’s full transfer history. There’s an entire class of questions that simply can’t be answered directly by blockchains: for instance, computing last week’s transaction volumes on a popular decentralized exchange is a non-starter. And watching for new blocks as they're mined is a whole other ball of wax.

Introducing ChainDisco…

In our opinion, there’s nothing more bracingly bizarre on blockchains today than NFTs. We built ChainDisco to highlight this madness by showing a Matrix-esque waterfall of the latest NFT transactions across the entire Ethereum blockchain:

We hope that ChainDisco makes it fun to explore the weird world of NFTs. This said, ChainDisco has no direct facility for purchasing. That’s because NFTs — like most crypto assets today — are purely speculative. Yes, they’re amusing and, frankly, more than a little disturbing to look at. (One of our kids calls ChainDisco “the creepy head picture site”.) But nothing good comes of speculation at scale; we’re content to look, not buy.

…and the BeQue API

Building ChainDisco taught us that working with blockchain data at scale — identifying relevant smart contracts, teasing apart transactions, mucking with metadata, and processing new blocks rapidly enough so that even 30-second-old events appear on the ChainDisco website — is challenging.

In the past few months, we’ve said hello to several other developers who have been forced to build their own homegrown blockchain data pipelines. This looks to us like undifferentiated heavy lifting. If (if!) blockchains are part of the future, we’re going to need better tools.

Under the hood, ChainDisco is built on top of a new API that we’re calling BeQue. We’re excited to share a bit about it today. BeQue’s goal is to make it absurdly simple for developers to issue complex queries against data in blockchains and related systems, and to get updates when new data is available. Like this:

Want to get the top 100 NFT trades this week?

import { Trade } from "@beque/nft";
// Ask BeQue to find the top 100 NFT trades this week
const topTrades = await Trade.query()
  .where("date", ">=", ONE_WEEK_AGO)
  .orderBy("-usdAmount")
  .limit(100);
// We have data (including some off-chain data!)
console.log(`${nft.name} purchased for ${nft.usdAmount}; see it here: ${nft.imageUrl}`);

Or get notified when an NFT trades for more than a million bucks?

import { Trade } from "@beque/nft";
import { Webhook } from "@beque/push";
// Define a query that listens for million-dollar NFT trades
const query = Trade.query().where("usdAmount", ">=", 1_000_000);
// Listen to this query. BeQue will call our Webhook HTTP endpoint
// when new blocks are mined and our query has relevant new results.
const listener = await Webhook.listen(query);

Get the total SOL ever sent from one account to another?

import { Account, Transaction } from "@beque/base-sol";
// Ask BeQue to sum all transactions from account1 to account2
const account1 = new Account(ADDRESS_1);
const account2 = new Account(ADDRESS_2);
const total = await Transaction.query()
  .where("from", account1)
  .where("to", account2)
  .sum("sol");

Or compute yesterday’s Uniswap volumes?

import { Trade } from "@beque/defi";
// Ask BeQue to sum all trades for Uniswap in the last day
const total = await Trade.query()
  .where("date", ">=", ONE_DAY_AGO)
  .where("exchange", "Uniswap")
  .sum("usdAmount");

BeQue is still in its infancy. The amount and variety of data generated on-chain today is staggering; the road ahead is long. If (again, if!) blockchains are around for the long term, we might expect them to contain plenty of interesting (and hopefully non-speculative) data. As a result, we think that an API that covers a wide terrain with a unified approach has potential.

So that’s it: we hope you have disturbing fun exploring with ChainDisco and enjoy taking a look at the nascent BeQue API. If you’d like to build with BeQue, please get in touch with us; we’d love to hear more about what you’re making.