0.0.4 • Published 1 year ago

@execute.dev/query-builder-sdk v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@execute.dev/query-builder-sdk

Helper types to build third-party integrations for the Execute Explorer.

Installation

npm install @execute.dev/query-builder-sdk

Usage

import { Query, QueryOptions, QueryRunner } from '@execute.dev/query-builder-sdk';

// define your plugin metadata
const plugin = new Query({
  module: 'YOUR_APP_ID',
  name: 'PLUGIN_NAME',
  description: 'PLUGIN_DESCRIPTION',
  options: {
    param1: {
      description: 'PARAM1_DESCRIPTION',
      type: 'STRING',
      required: true,
    },
    param2: {
      description: 'PARAM2_DESCRIPTION',
      type: 'ADDRESS',
      required: false,
    },
  },
});

// create your plugin handler function
const handler = async (query: QueryOptions, runner: QueryRunner) => {
  // if it reaches here, the query is valid and the user has access to the plugin

  // do something
  // read contracts using our super fast indexer
  const contractData = await runner.readContract('0x123', 'balanceOf', ['0x456']);
  // or make web requests using an infinite pool of auto-routing proxies
  const response = await runner.webRequest('https://api.coingecko.com/api/v3/coins/ethereum');

  // report compute used for every step]
  runner.reportComputeUnits(20, 'did xyz');

  // save and get state to be used across users
  await runner.saveGlobalState('foo', JSON.stringify({ foo: 'bar' }));
  const globalState = await runner.getGlobalState('foo');

  // save and get state to be used only by the current user
  await runner.saveUserState('foo', JSON.stringify({ foo: 'bar' }));
  const userSpecificState = await runner.getUserState('foo');

  // store and retrieve cache data on-demand
  await runner.setCache('foo', 'bar');
  const cache = await runner.getCache('foo');
};

License

MIT