Preview Release See the table of contents

Introduction to BeQue

BeQue is an HTTP API that makes it easy to ask complex questions about the Solana and Ethereum blockchains and get data back, lightning fast.

If you’ve done development with blockchains before, you know that you can issue simple queries against them directly, usually with their JSON-RPC endpoints. For example, it’s easy to ask “what is this account’s current balance” without doing anything too fancy.

BeQue lets you ask those basic questions… and a whole bunch of questions that are basically impossible to ask directly. Even better, BeQue can send you real-time query update notifications whenever new blocks are mined.

BeQue is in early preview mode

Our long-term goal for BeQue is to build the Web3/crypto data API that developers love to use.

Ultimately, we think this needs to cover a huge surface area: multiple blockchains, data found both on- and off-chain (like NFT images and metadata, or DAO vote logs), specialized smart contracts like popular DeFi services, etc.

Obviously, this is a huge surface area; we want to be clear that BeQue can only do a miniscule fraction of this today.

If you think a developer-facing API like BeQue would be useful for you, please send us an email; we’d love to hear about what you’re building.

A first taste of BeQue

For example, instead of asking about an account’s current balance, let’s say you wanted to ask about its average balance over the last month. BeQue makes this a snap:

import { Account, Transaction } from "@beque/base-eth";

const account = new Account(ADDRESS);
const balance = await Transaction.query()
  .where("date", ">=", ONE_MONTH_AGO)
  .where(["from", "to"], account)
  .avg("accountBalance");

That’s it: a complex query and a useful result in just a few lines of code.

The example above uses our TypeScript SDK, as do most of the examples in our documentation. If you happen to work with JavaScript or TypeScript, we definitely recommend using our SDK! If you’re writing code in another language, you’ll want to read up on how to make direct HTTP requests to BeQue instead. If there’s a language you’d like to see an SDK for, please send us an email and let us know.

Getting real-time notifications

Here’s where things get extra fun.

Let’s say you want to know anytime an account has a new transaction, so you can recompute its average. BeQue lets you get webhook callbacks:

import { Account, Transaction } from "@beque/base-sol";
import { Webhook } from "@beque/push";

const account = new Account(ADDRESS);
const accountTransactionQuery = Transaction.query().where(
  ["from", "to"],
  account
);

// Listen to this query. BeQue will call our Webhook HTTP endpoint
// when new blocks are mind and our query has relevant new results.
const listener = await Webhook.listen(accountTransactionQuery);

That’s it. After those lines of code, BeQue will call your webhook URL any time there’s a new transaction associated with the account. From there, you can recompute the average balance, or do anything else you’d like. See working with webhooks for details.

You’ll notice that BeQue uses the same query syntax whether you’re issuing the query right now, or whether you’re asking to get called back later when there are new results. This makes it amazingly easy to generate historical views of the data you want and update them in real-time as the blockchains grow.