dune-client

This is currently in pre-alpha state with no error handling, but can get the job done

Usage no npm install needed!

<script type="module">
  import duneClient from 'https://cdn.skypack.dev/dune-client';
</script>

README

A client for Dune Analytics Build Status npm

This is currently in pre-alpha state with no error handling, but can get the job done

Installation

npm i -g dune-client

Then set your env variables (todo: better auth for cli):

# Your session cookie from browser
export SESSION=
# The client needs one of your queries to use as a workspace
export QUERY_ID=

Usage

# table mode
$ dune-cli --table 'select block_number, block_time from ethereum.traces limit 5'
submitting: waiting
submitting: done
executing: waiting
executing: done
fetching results
fetched 5 rows
┌─────────┬──────────────┬────────────────────────┐
│ (index) │ block_number │       block_time       │
├─────────┼──────────────┼────────────────────────┤
│    0    │    46147     │ '2015-08-07T03:30:33Z' │
│    1    │    46169     │ '2015-08-07T03:36:53Z' │
│    2    │    46170     │ '2015-08-07T03:37:10Z' │
│    3    │    46194     │ '2015-08-07T03:43:03Z' │
│    4    │    46205     │ '2015-08-07T03:46:15Z' │
└─────────┴──────────────┴────────────────────────┘

# JSON mode
$ dune-cli 'select block_number, block_time from ethereum.traces limit 5'
submitting: waiting
submitting: done
executing: waiting
executing: done
fetching results
fetched 5 rows
[
  { block_number: 46147, block_time: '2015-08-07T03:30:33Z' },
  { block_number: 46169, block_time: '2015-08-07T03:36:53Z' },
  { block_number: 46170, block_time: '2015-08-07T03:37:10Z' },
  { block_number: 46194, block_time: '2015-08-07T03:43:03Z' },
  { block_number: 46205, block_time: '2015-08-07T03:46:15Z' }
]

# Piping input and output (progress messages are printed to stderr)
$ echo 'select block_number, block_time from ethereum.traces limit 5' | dune-cli | jq '.[2:4]'
submitting: waiting
submitting: done
executing: waiting
executing: done
fetching results
fetched 5 rows
[
  {
    "block_number": 46170,
    "block_time": "2015-08-07T03:37:10Z"
  },
  {
    "block_number": 46194,
    "block_time": "2015-08-07T03:43:03Z"
  }
]

Use as a package

const DuneClient = require('dune-client')

async function main() {
  const dune = new DuneClient(session, queryId)
  const rows = await dune.query('select * from ethereum.traces limit 10')
  console.log(rows)
}