API Calls are now included in the dune free tier, which makes this library obsolete.
You should rather follow the dune documentation to make programmatic calls to the Dune API.
Dune TS
Unofficial Dune Analytics Typescript Client.
Motivation
Dune Analytics is a great tool for querying blockchain data.
However, it is currently only browser based which is not very developer friendly. An official API is being developed but
is only opened in private beta.
This library aims to provide an alternative way to integrate Dune Analytics into your Typescript projects.
Features
Installation
pnpm add dune-ts
yarn add dune-ts
npm install dune-ts
Setup
Define DUNE_PASSWORD
and DUNE_USERNAME
environment variables.
Alternatively, you can pass the credentials to the Dune
constructor.
Local Development
Setup: npm run setup
Check available scripts: nps
Fetch Query Results: nps "query -q <query-id> -u <username> -p <password>"
How To Use
Dune.query
requires a queryId
(can be looked up in the URL of the query https://dune.com/queries/<queryId>
) and accepts an optional array describing your query parameters (that you defined in the online query editor).
- number parameter:
{ key: 'parameterName', value: '123', type: 'number' }
- text parameter:
{ key: 'parameterName', value: '123', type: 'text' }
- date parameter:
{ key: 'parameterName', value: new Date(), type: 'datetime' }
- list parameter: not supported by this lib yet
import { Dune } from 'dune-ts'
const dune = new Dune({ password, username })
const { columns, data } = await dune.query(queryId, [
{ key: 'key', value: 'value', type: 'text' },
])
Disclaimer
This is an experimental library. It'll break as soon as Dune Analytics change their graphql endpoints (URL or parameters).
This isn't free of bugs either. Contributions are welcome!
Credits
Based on itzmestar/duneanalytics