SDK
moloch-v3-data

@daohaus/moloch-v3-data

Moloch v3 data encapsulate our subgraphs, empowering you to perform common queries across diverse entities with ease. The library is designed with optimization at its core, transforming the data you receive into a user-friendly and easy-to-manipulate format.

The library's functions let you find single entities or query lists, and the list queries are supplemented with several helper tools for pagination, filtering, and sorting.

Github (opens in a new tab)

Query


NPM (opens in a new tab)

Functions

Usage

Installation

yarn add @daohaus/moloch-v3-data

Requirements

If you are trying to query for data on Etheruem Mainnet or Gnosis Chain (and more to come) you will need to provide an API key from The Graph. Learn to get those keys here (opens in a new tab) and here (opens in a new tab).

Examples

How to find a single entity by ID

import { findDao } from '@daohaus/moloch-v3-data';
 
const daoRes = await findDao({
  networkId: '0x1',
  dao: '0x0DaoContractAddress',
  includeTokens: true,
  graphApiKeys: {
    '0x1': 'graphApiKey',
  },
});

How to find a a list of entities

import {
  listProposals,
  Proposal_Filter,
  Proposal_OrderBy,
} from '@daohaus/moloch-v3-data';
 
const list = await listProposals({
  networkId: '0x1',
  filter: {
    createdAt_gte: '1656693140',
  },
  ordering: {
    orderBy: 'createdAt',
    orderDirection: 'asc',
  },
  paging: {
    pageSize: '20',
    offset: '1',
  },
  graphApiKeys: {
    '0x1': 'graphApiKey',
  },
});

Filtering

Provide any query the graph supports on fields within the entity you are querying. The Graph docs contain examples on filtering (opens in a new tab).

Ordering

Provide a field to order by and the order direction (asc or desc).

Paging

The SDK supports offest and cursor pagination. Cursor pagination overrides the ordering to the ID field. Pagination defaults to returning the first 100 results and provides the query required to get to the next page.

{
  pageSize: '20',
  offset: '0'
}
 
{
  pageSize: '2000',
  lastId: '0'
}