DEV Community

Sort
Sort

Posted on • Updated on

The new Sort NPM package for querying Ethereum data with SQL

We're excited to release a new NPM package for querying decoded Ethereum transactions with SQL. Results in milliseconds, using an in-memory column store, we want to remove the need to manage a backend for your dApp!

Our NPM package is the next step in making "Hello World" to Web3 as simple as possible, expect a few more similar developments from Sort as we put the final touches on a new Ethereum "Hello World" tutorial that will push the ecosystem forward.

Quick Start

const { Sort }  = require('sort-xyz');

// initialize Sort client using free api key from sort.xyz
let sort = new Sort({ api_key: 'ce4c9316-f7ce-4955-b6b3-2292a8be7afa' });

let result = await sort.query("select * from ethereum_latest.transaction_log l where l.name = 'Nested' limit 10");
Enter fullscreen mode Exit fullscreen mode

API keys are free, and available at sort.xyz. The Sort NPM package overview is listed here.

Run a SQL query

Formulate the query at sort.xyz, then run the query directly in your application.

// send a SQL query to sort

let result = await sort.query("select _id as hash, value_eth as amount, timestamp, t.function.params[1].value as punkId from ethereum_latest.transaction t where t.to = '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb' and t.function.name = 'buyPunk' order by timestamp desc limit 100");
Enter fullscreen mode Exit fullscreen mode

You can also use the query id from the Sort UI to minimize the amount of SQL within your code:

// query id obtained from the id at sort.xyz
// -> create a query on sort.xyz
// -> save the query
// -> obtain the query id from the URL: https://sort.xyz/query/<QUERY ID>

let result = await sort.queryById('62f7d1001a096c757ce8f355');
Enter fullscreen mode Exit fullscreen mode

Latest decoded transactions for a contract address

// get latest 100 transactions for the OpenSea Seaport contract
let result = await sort.contractTransactions(
  '0x00000000006c3852cbef3e08e8df289169ede581');

// get latest 10 transactions for the OpenSea Seaport contract
let result = await sort.contractTransactions(
  '0x00000000006c3852cbef3e08e8df289169ede581', 10);
Enter fullscreen mode Exit fullscreen mode

Latest decoded contract events / logs

// get latest 100 events/logs for the OpenSea Seaport contract
let result = await sort.contractEvents(
  '0x00000000006c3852cbef3e08e8df289169ede581');

// get latest 10 events/logs for the OpenSea Seaport contract
let result = await sort.contractEvents(
  '0x00000000006c3852cbef3e08e8df289169ede581', 10);
Enter fullscreen mode Exit fullscreen mode

Decoded transaction by hash

let result = await sort.transaction("0x32ef066346ed78ceac0f6fdb888adf44819856564b8268985c3f09a68c8c4ddb");
Enter fullscreen mode Exit fullscreen mode

And also decoded transaction events / logs by hash

let result = await sort.transactionEvents("0x32ef066346ed78ceac0f6fdb888adf44819856564b8268985c3f09a68c8c4ddb");
Enter fullscreen mode Exit fullscreen mode

Focus on client-side code, Sort will be your backend

All of these examples can run directly in Javascript, with a public API key (no secrets needed). This means there is no longer a need to host a backend server. Simplify your Ethereum app development and use Sort as your backend!

Top comments (0)