@terminal-packages/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.1.7 • Public • Published

npm version downloads Twitter Follow Discord Channel

Terminal-logo

| Setup Guide | Basic Wallet Providers | MetaMask Provider | Custom Http Providers | Websockets | Basic RPC Endpoints |

TerminalSDK - Dapp Monitoring & Analytics

Terminal is the best platform for managing and monitoring dapps. From testing to production, Terminal provides you with everything you need to properly monitor your blockchain infrastructure, application, transactions, users and more in one place.

TerminalSDK allows you to surface logs from arbitrary RPC endpoints, networks, and injected wallet providers to your Terminal account. TerminalSDK is a simple drop-in wrapper around any Web3 provider with minimal configuration required on your part to get up and running.

  • Drop in the Terminal subprovider to get Dapp specific activity feeds and analytics
  • Surface logs, transactions, and new & return user feeds
  • Aggregated analytics across your dapp's transactions, users, and infrastructure
  • Compatible with web3.js and ethers.js
  • Introduce cloud logging into your Truffle development environment
  • Log subgraph queries with TerminalApolloLink
  • Record and visualize 0x-mesh node activity

Setup Guide

Step 1

To install, do the following:

npm:

$ npm install @terminal-packages/sdk

yarn:

$ yarn add @terminal-packages/sdk

Step 2

Now that you've installed the sdk, you will need to signup for a Terminal account and generate an API key. You can make an account by going to https://terminal.co and clicking 'signup'. Once you have made an account, you can easily generate an API key by clicking on the profile icon in the top right corner and clicking 'settings'. You can then generate a new API key at the bottom of the page.

Step 3

Once you've signed up and generated an API key, you will be able to wrap any external source in the TerminalSDK and surface logs. Choose which type of external source you'd like to wrap first and follow the instructions below or at the tech docs. If you are trying to get MetaMask logs, you can go ahead and skip to the bottom of the page or click here.

Step 4

Now that you have wrapped your desired external source in the TerminalSDK, navigate to the logs page and check that your newly added source is surfacing logs. We recommend making a few test calls to each source in order to ensure it is working properly. If you are having trouble setting up logs for your external sources, please feel free to reach out on our Discord.

TerminalHttpProvider Options

host: Any ethereum provider url of your choice
apiKey: An API key associated with your Terminal account
source: Any custom provider of your choice

*source can be any dynamic string of your choice or use one of the basic sourceTypes listed below

Changelog

View changelog

Developer docs

View develop-docs

Contents

  1. TerminalHttpProvider

  2. TerminalWebsocketProvider

  3. MetaMask

  4. WalletConnect dapps logging (browser)

  5. 0x Mesh RPC Client - (browser)

  6. Custom logging

  7. IPFS

  8. Apollo GraphQL

TerminalHttpProvider

Hooking this custom provider up is super easy and once hooked up it will push all JSON-RPC calls to your logs in your Terminal account.

Due to the rewrite of web3 for 2.0 the code on web3 1 vs web3 2 is very different, this means we have to go down different paths of code depending on the version you use. We made this super easy for you to tell us in the examples below. By default if you do not supply it then it will default to 2.0. Please note if your on 1.0-beta version you do not need to supply the web3 version.

web3 http

https://www.npmjs.com/package/web3

Basic provider options

export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
}

Please note if your on 1.0-beta then Web3Versions.two is the correct version.

export enum Web3Versions {
  one = '1',
  two = '2',
}

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

With web3 provider options

  • timeout - optional
  • headers - optional
  • withCredentials - optional

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options is not required
    options: {
      // timeout is not required
      timeout: 10000,
      // headers is not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // with credentials is not required
      withCredentials: true
    }
  })
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
     // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options is not required
    options: {
      // timeout is not required
      timeout: 10000,
      // headers is not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // with credentials is not required
      withCredentials: true
    }
  })
);

With your own http provider

If you're using your own custom provider it should be following the standard HttpProvider interface which exposes a property called host on your provider itself. Without this we do not know the nodeUrl which means you don't get that information when you go and view your logs. If you want to log the nodeUrl as well you just need to expose a host property on your provider and the sdk will grab it and start saving all logs with that nodeUrl as that property.

JavaScript/TypeScript
import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: new YourCustomHttpProvider(),
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: new YourCustomHttpProvider(),
  }),
);

ethers http

https://www.npmjs.com/package/ethers

Basic provider options

export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
}

Please note if your on 1.0-beta then Web3Versions.two is the correct version if you ever want to supply the Web3Versions to a call.

export enum Web3Versions {
  one = '1',
  two = '2',
}

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const provider = new ethers.providers.Web3Provider(
  new sdk.TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

With web3 provider options

  • timeout - optional
  • headers - optional
  • withCredentials - optional
JavaScript/TypeScript
import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options is not required
    options: {
      // timeout is not required
      timeout: 10000,
      // headers is not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // with credentials is not required
      withCredentials: true
    }
  })
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const provider = new ethers.providers.Web3Provider(
  new sdk.TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
     // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options is not required
    options: {
      // timeout is not required
      timeout: 10000,
      // headers is not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // with credentials is not required
      withCredentials: true
    }
  })
);

With your own http provider

If you're using your own custom provider it should be following the standard HttpProvider interface which exposes a property called host on your provider itself. Without this we do not know the nodeUrl which means you don't get that information when you go and view your logs. If you want to log the nodeUrl as well you just need to expose a host property on your provider and the sdk will grab it and start saving all logs with that nodeUrl as that property.

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: new YourCustomHttpProvider(),
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const provider = new ethers.providers.Web3Provider(
  new sdk.TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: new YourCustomHttpProvider(),
  }),
);

Injected window.ethereum from other 3rd party wallets who use http provider

Please note that if you're using MetaMask please follow the guide here.

Our provider handle any injected custom provider in the window. If you're using a 3rd party wallet which injects the custom provider in the window.ethereum you can use that with our provider. All you have to do is pass in the window.ethereum into the customHttpProvider option within the TerminalHttpProvider class. Example below shows how you would do this:

Web3

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: window.ethereum,
  }),
);

Ether

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalHttpProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customHttpProvider: window.ethereum,
  }),
);

TerminalWebsocketProvider

Due to the rewrite of web3 for 2.0 the code on web3 1 vs web3 2 is very different, this means we have to go down different paths of code depending on the version you use. We made this super easy for you to tell us in the examples below. By default if you do not supply it then it will default to 2.0. Please note if your on 1.0-beta version you do not need to supply the web3 version.

web3 websocket

https://www.npmjs.com/package/web3

export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
  Torus = 'Torus',
  GNOSIS = 'GNOSIS',
  ZeroXMesh = '0x-Mesh',
}

Please note if your on 1.0-beta then Web3Versions.two is the correct version if you ever want to supply the Web3Versions to a call.

export enum Web3Versions {
  one = '1',
  two = '2',
}

Basic provider options

JavaScript/TypeScript

import {
  TerminalWebsocketProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

With web3 provider options

  • timeout - optional
  • headers - optional
  • protocol - optional
  • clientConfig - optional

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options not required
    options: {
      // timeout not required
      timeout: 10000,
      // headers not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // protocol not required
      protocol: '63',
      // client config not required
      clientConfig: {
        maxReceivedFrameSize: 100000000,
        maxReceivedMessageSize: 100000000
      },
    }
  })
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options not required
    options: {
      // timeout not required
      timeout: 10000,
      // headers not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // protocol not required
      protocol: '63',
      // client config not required
      clientConfig: {
        maxReceivedFrameSize: 100000000,
        maxReceivedMessageSize: 100000000
      },
    }
  })
);

With your own websocket provider

If you're using your own custom provider we look for a property called host on your provider itself. Without this we do not know the nodeUrl which means you don't get that information when you go and view your logs. If you want to log the nodeUrl as well you just need to expose a host property on your provider and the sdk will grab it and start saving all logs with that nodeUrl as that property.

JavaScript/TypeScript
import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: new YourCustomWebsocketProvider(),
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: new YourCustomWebsocketProvider(),
  }),
);

Ethers websocket

https://www.npmjs.com/package/ethers

Basic provider options

export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
}

Please note if your on 1.0-beta then Web3Versions.two is the correct version if you ever want to supply the Web3Versions to a call.

export enum Web3Versions {
  one = '1',
  two = '2',
}

JavaScript/TypeScript

import {
  TerminalWebsocketProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const provider = new ethers.providers.Web3Provider(
  new sdk.TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
  }),
);

With web3 provider options

  • timeout - optional
  • headers - optional
  • withCredentials - optional

JavaScript/TypeScript

import {
  TerminalHttpProvider,
  SourceType,
  Web3Versions
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const web3 = new ethers.providers.Web3Provider(
  new TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: SourceType.Terminal,
       // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
     // networkSource can be a dynamic string as well
     // it's also not required
    networkSource: SourceType.Infura,
    // options not required
    options: {
      // timeout not required
      timeout: 10000,
      // headers not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // protocol not required
      protocol: '63',
      // client config not required
      clientConfig: {
        maxReceivedFrameSize: 100000000,
        maxReceivedMessageSize: 100000000
      },
    }
  })
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const web3 = new ethers.providers.Web3Provider(
  new sdk.TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'YOUR_API_KEY',
    projectId: "YOUR_TERMINAL_PROJECT_ID",
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    // options not required
    options: {
      // timeout not required
      timeout: 10000,
      // headers not required
      headers: [{ name: 'x-custom-header' value: 'example' }],
      // protocol not required
      protocol: '63',
      // client config not required
      clientConfig: {
        maxReceivedFrameSize: 100000000,
        maxReceivedMessageSize: 100000000
      },
    }
  })
);

With your own websocket provider

If you're using your own custom provider we look for a property called host on your provider itself. Without this we do not know the nodeUrl which means you don't get that information when you go and view your logs. If you want to log the nodeUrl as well you just need to expose a host property on your provider and the sdk will grab it and start saving all logs with that nodeUrl as that property.

JavaScript/TypeScript
import {
  TerminalWebsocketProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const web3 = new ethers.providers.Web3Provider(
  new TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: new YourCustomWebsocketProvider(),
  }),
);

Node

const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const web3 = new ethers.providers.Web3Provider(
  new sdk.TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: sdk.SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: sdk.Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: new YourCustomWebsocketProvider(),
  }),
);

Injected window.ethereum from other 3rd party wallets who use websocket provider

Please note that if you're using MetaMask please follow the guide here and they only support http provider.

Our provider handle any injected custom provider in the window. If you're using a 3rd party wallet which injects the custom provider in the window.ethereum you can use that with our websocket provider. All you have to do is pass in the window.ethereum into the customWebsocketProvider option within the TerminalWebsocketProvider class. Please note your window.ethereum provider must support websockets for this to work. Example below shows how you would do this:

Web3

import {
  TerminalWebsocketProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import Web3 from 'web3';

const web3 = new Web3(
  new TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: window.ethereum,
  }),
);

Ether

import {
  TerminalWebsocketProvider,
  SourceType,
  Web3Versions,
} from '@terminal-packages/sdk';
import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(
  new TerminalWebsocketProvider({
    apiKey: 'YOUR_API_KEY',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    // if your using web3 1 (NONE BETA) please tell us, if you're not please delete this property
    web3Version: Web3Versions.one,
    // networkSource can be a dynamic string as well
    // it's also not required
    networkSource: SourceType.Infura,
    customWebsocketProvider: window.ethereum,
  }),
);

MetaMask

https://metamask.io/

Logging

MetaMask options:

export interface IMetaMaskOptions {
  apiKey: string;
  projectId?: string | undefined;
}

Please note that if you're only using the logging MetaMask feature, you do not need to install the sdk as well.

To get all the amazing logging in your dapp, all you need to do is paste this script within the <head> tag of your website:

<!-- TERMINAL SCRIPTS -->
  <script src="https://storage.googleapis.com/terminal-sdk/metamask/latest/metamask-latest.min.js"></script>
  <script type="text/JavaScript">
      window.terminal.sdk.metamask.startLogging({
        apiKey: 'YOUR_API_KEY',
        projectId: 'YOUR_PROJECT_ID',
        // networkSource is optional
        networkSource: "Infura",
        // if your using web3 2 please define the below
        // if your using web3 1.0 you do not need this line
        web3Version: Web3Versions.two,
      });
  </script>
<!-- END TERMINAL SCRIPTS -->

This will expose a window.terminal.ethereum which you can inject into any web3 instance

import Web3 from 'web3';

const web3 = new Web3(window.terminal.ethereum);

For legacy dapps which still use window.web3 injected by MM using that will start logging everything. We highly recommend not doing this as MM use 0.2.x web3 which uses callbacks. Using the above approach and using 1.x.x or 2.x.x will allow you to use promises.

If you want to use a fixed version of the MetaMask script you can. We deploy every version of the script to the CDN store against the same version as the sdk when that's deployed. You can hook in those fixed versions by replacing {{versionInfo}} with your version number you want to use.

<script src="https://storage.googleapis.com/terminal-sdk/metamask/{{versionNumber}}/metamask-{{versionNumber}}.min.js" />

WalletConnect dapps logging

https://walletconnect.org/

https://docs.walletconnect.org/quick-start/dapps

WalletConnect dapps logging does not go through web3 or etherjs and uses its own npm package to establish connections with the wallets it supports. To be able to start logging WalletConnect jsonrpc calls to your terminal project all you need to do is:

walletConnectOptions:

export interface IWalletConnectOptions {
  bridge: string;
  session?: IWalletConnectSession;
}

or

export interface IWalletConnectOptions {
  uri: string;
  session?: IWalletConnectSession;
}

example is shown using WalletConnect bridge logic.

const walletConnector = new TerminalWalletConnectBrowserProvider({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  walletConnectOptions: {
    bridge: 'https://bridge.walletconnect.org',
  },
});

// now use `walletConnector` as you would use it in the WalletConnect documentation and everything will be logged for you

It will pick up the source for you automatically and link it to the WalletConnect wallet it is connected to. So for example if you are connected to Trust wallet the source will save in your terminal logs as TrustWallet.

If you are using a version of wallet connect that has some new features and our sdk is still using a old WalletConnect package, you can pass us a wallet connect instance and it will use your instance instead of ours:

const walletConnector = new TerminalWalletConnectBrowserProvider({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  walletConnectInstance: new WalletConnect({
    bridge: 'https://bridge.walletconnect.org',
  }),
  walletConnectOptions: {
    bridge: 'https://bridge.walletconnect.org',
  },
});

// now use `walletConnector` as you would use it in the WalletConnect documentation and everything will be logged for you

0x Mesh

https://0x-org.gitbook.io/mesh/json-rpc-clients/typescript

https://github.com/0xProject/0x-mesh

0x Mesh WSClient is a RPC client for the custom methods a 0x-Mesh Node exposes. With TerminalWSClientProvider you can use all the functionalities knowing that RPC calls will be logged to Terminal. Here is an example:

const wsclientInstance = new TerminalWSClientProvider({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  wsOptions: { url: 'ws://YOUR_NODE:60557' },
});

wsclientInstance.getStatsAsync().then(console.log)

Custom Logging

In some cases you may not be using web3 or etherjs to do your jsonrpc calls and executing them yourself. If so you can save the logs directly to us meaning you still get the power of the log views on terminal.

The request object is:

export interface ISaveLogRequest {
  id: number;
  jsonrpc: string;
  nodeUrl: string;
  method: string;
  parameters: any[];
  // stringify result from jsonrpc call
  result: string | null;
  source: string;
  isError: boolean;
  responseTimeMs?: number | undefined;
  chainId?: string | undefined;
  // stringify result from user custom headers
  headers: string;
  projectId?: string | undefined;
  fromAddress?: string | undefined;
  networkSource?: string | undefined;
}
export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
}

JavaScript/TypeScript

import { TerminalLogApiProvider, SourceType } from '@terminal-packages/sdk';

const apiProvider = new TerminalLogApiProvider({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
});

await apiProvider.saveJsonRpcLog({
  id: 4,
  jsonrpc: '2.0',
  nodeUrl: 'mocknode',
  method: 'eth_getBalance',
  parameters: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'],
  result: '0x0',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
  isError: false,
  responseTimeMs: 1250,
  chainId: '1',
  headers:
    "[{'name':'Access-Control-Allow-Origin','value':'https://rinkeby.infura.io/v3/key'}]",
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  networkSource: SourceType.Infura,
});

Node

const sdk = require('@terminal-packages/sdk');

const apiProvider = new sdk.TerminalLogApiProvider({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
});

await apiProvider.saveJsonRpcLog({
  id: 4,
  jsonrpc: '2.0',
  nodeUrl: 'mocknode',
  method: 'eth_getBalance',
  parameters: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'],
  result: '0x0',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
  isError: false,
  responseTimeMs: 1250,
  chainId: '1',
  headers:
    "[{'name':'Access-Control-Allow-Origin','value':'https://rinkeby.infura.io/v3/key'}]",
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  networkSource: sdk.SourceType.Infura,
});

IPFS

If you use IPFS we can log that as well for you. We only support the public API infura supports for now.

IPFS logging

block

block_get

Get a raw IPFS block.

Request params

arg [required] - The base58 multihash of an existing block to get.

Response

Promise<string> - This endpoint returns a text/plain response body.

JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.block.get(
  'QmaYL7E4gDTPNfLxrCEEEcNJgcHBJ55NxxTnxpDKWqMtJ3',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.block.get(
  'QmaYL7E4gDTPNfLxrCEEEcNJgcHBJ55NxxTnxpDKWqMtJ3',
);

console.log(response);

block_stat

Print information of a raw IPFS block.

Request params

arg [required] - The base58 multihash of an existing block to stat.

Response
export interface IBlockStatResponse {
  /**
   * The base58 multihash string of the block
   */
  Key: string;
  /**
   * An integer representing the size in bytes
   */
  Size: number;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.block.stat(
  'QmfQ5QAjvg4GtA3wg3adpnDJug8ktA1BxurVqBD8rtgVjM',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.block.stat(
  'QmaYL7E4gDTPNfLxrCEEEcNJgcHBJ55NxxTnxpDKWqMtJ3',
);

console.log(response);

block_put

Store input as an IPFS block.

Request params

fileStringOrBlob [Required] - The file string or blob data

format [Optional] - cid format for blocks to be created with. Default: “v0”.

mhtype [Optional] - multihash hash function. Default: “sha2-256”.

mhlen [Optional] - multihash hash length. Default: “-1”.

export interface IBlockPutRequest {
  /**
   * The file string or blob data
   */
  fileStringOrBlob: string | Blob;
  /**
   * cid format for blocks to be created with. Default: “v0”.
   */
  format?: string | undefined;
  /**
   * multihash hash function. Default: “sha2-256”.
   */
  mhtype?: string | undefined;
  /**
   * multihash hash length. Default: “-1”.
   */
  mhlen?: number | undefined;
}
Response
Promise<IBlockPutResponse>
export interface IBlockPutResponse {
  /**
   * Key of the block
   */
  Key: string;
  /**
   * Integer indication size in bytes
   */
  Size: number;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.block.put({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.block.put({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);

cat

Show IPFS object data.

Request params

arg [required] - The IPFS object hash.

Response

Promise<string> - This endpoint returns a text/plain response body.

JavaScript/TypeScript

import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.cat(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.cat(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

dag

dag_get

Get a dag node from IPFS.

Request params

arg [required] - The IPFS object hash

Response
export interface IDagGetResponse {
  /**
   * The data
   */
  data: string;
  /**
   *  An array of associated link objects
   */
  links: any[];
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.dag.get(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.dag.get(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

dag_resolve

Resolve IPLD block.

Request params

arg [required] - The IPFS object hash; the path to resolve.

Response
export interface IDagResolveResponse {
  /**
   * The content ID
   */
  Cid: { '/': string };
  /**
   * The rem path
   */
  RemPath: string;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.dag.resolve(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.dag.resolve(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

dag_put

Add a dag node to IPFS.

Request params

fileStringOrBlob [Required] - The file string or blob data

format [Optional] - cid format for blocks to be created

pin [Optional] - Pin this object when adding. Default: “true”.

input-enc [Optional] - Format that the input object will be. Default: “json”.

hash [Optional] - Hash function to use.

export interface IDagPutRequest {
  /**
   * The file string or blob data
   */
  fileStringOrBlob: string | Blob;
  /**
   * cid format for blocks to be created
   */
  format?: string | undefined;
  /**
   * Pin this object when adding. Default: “true”.
   */
  pin?: boolean | undefined;
  /**
   * Format that the input object will be. Default: “json”.
   */
  inputEnc?: InputEnc | undefined;
  /**
   * Hash function to use.
   */
  hash?: MultihashTypes | undefined;
}

export enum InputEnc {
  protobuf = 'protobuf',
  json = 'json',
}

export enum MultihashTypes {
  sha1 = 'sha1',
  sha2_256 = 'sha2-256',
  sha2_512 = 'sha2-512',
  sha3 = 'sha3',
  sha3_224 = 'sha3-224',
  sha3_256 = 'sha3-256',
  sha3_384 = 'sha3-384',
  sha3_512 = 'sha3-512',
  dbl_sha2_256 = 'dbl-sha2-256',
  // infura dont support this right now
  murmur3_128 = 'murmur3-128',
  // not implemented by infura
  keccak_224 = 'keccak-224',
  // not implemented by infura
  keccak_226 = 'keccak-226',
  // not implemented by infura
  keccak_384 = 'keccak-384',
  keccak_512 = 'keccak-512',
  shake_128 = 'shake-128',
  shake_256 = 'shake-256',
  // not implemented by infura
  x11 = 'x11',
  md5 = 'md5',
}
Response
Promise<IDagGetResponse>
export interface IDagGetResponse {
  /**
   * The data
   */
  data: string;
  /**
   *  An array of associated link objects
   */
  links: any[];
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.dag.put({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.dag.put({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);

get

Download IPFS objects.

Request params

arg [required] - The IPFS object hash.

output [optional] - The path where the output should be stored.

archive [optional] - Output a TAR archive. Default: “false”.

compress [optional] - Compress the output with GZIP compression. Default is “false”.

compression-level [optional] - The level of compression (1-9). Default: “-1”.

export interface IGetRequest {
  /**
   * The IPFS object hash
   */
  arg: string;
  /**
   * The path where the output should be stored.
   */
  output?: string | undefined;
  /**
   *  Output a TAR archive. Default: “false”.
   */
  archive?: boolean | undefined;
  /**
   * Compress the output with GZIP compression. Default is “false”.
   */
  compress?: boolean | undefined;
  /**
   * The level of compression (1-9). Default: “-1”.
   */
  'compression-level'?: CompressionLevel | undefined;
}

Response

Promise<string> - This endpoint returns a text/plain response body.

JavaScript/TypeScript

import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.get({
  arg: 'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
});

console.log(response);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.get({
  arg: 'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
});

console.log(response);

object

object_data

Output the raw bytes of an IPFS object.

Request params

arg [required] - Key of the object to retrieve, in base58-encoded multihash format.

Response

Promise<string> - This endpoint returns a text/plain response body.

JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.object.data(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.object.data(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

object_get

Get and serialize the DAG node named by key.

Request params

arg [required] - Key of the object to retrieve, in base58-encoded multihash format.

Response
Promise<IObjectGetResponse>
export interface IObjectGetResponse {
  /**
   * An array of associated link objects
   */
  Links: any[];
  /**
   * The data
   */
  Data: string;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.object.get(
  'QmfQ5QAjvg4GtA3wg3adpnDJug8ktA1BxurVqBD8rtgVjM',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.object.get(
  'QmfQ5QAjvg4GtA3wg3adpnDJug8ktA1BxurVqBD8rtgVjM',
);

console.log(response);

object_stat

Get stats for the DAG node named by key.

Request params

arg [required] - Key of the object to retrieve, in base58-encoded multihash format.

Response
Promise<IObjectStatResponse>
export interface IObjectStatResponse {
  /**
   * Hash of the object
   */
  Hash: string;
  /**
   * Number of links the node contains
   */
  NumLinks: number;
  /**
   * Size of the raw serialized node
   */
  BlockSize: number;
  /**
   * Size of the links block section
   */
  LinksSize: number;
  /**
   * Size of data block section
   */
  DataSize: number;
  /**
   * Size of the tree (BlockSize + link sizes)
   */
  CumulativeSize: number;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.object.stat(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.object.stat(
  'QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy',
);

console.log(response);

object_put

Store input as a DAG object, print its key.

Request params

fileStringOrBlob [Required] - The file string or blob data as a DAG object.

inputenc [Optional] - Encoding type of input data. One of: {“protobuf”, “json”}. Default: “json”.

datafieldenc [Optional] - Encoding type of the data field, either “text” or “base64”. Default: “text”.

pin [Optional] - Pin this object when adding. Default: “false”.

export interface IObjectPutRequest {
  /**
   *  The file string or blob data as a DAG object.
   */
  fileStringOrBlob: string | Blob;
  /**
   * Encoding type of input data. One of: {“protobuf”, “json”}. Default: “json”.
   */
  inputEnc?: InputEnc | undefined;
  /**
   * Encoding type of the data field, either “text” or “base64”. Default: “text”.
   */
  dataFieldEnc?: DataFieldEnc | undefined;
  /**
   * Pin this object when adding. Default: “false”.
   */
  pin?: boolean;
}

export enum DataFieldEnc {
  text = 'text',
  base64 = 'base64',
}

export enum InputEnc {
  protobuf = 'protobuf',
  json = 'json',
}
Response
Promise<IObjectPutResponse>
export interface IObjectPutResponse {
  /**
   * Hash of the object
   */
  Hash: string;
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.object.put({
  fileStringOrBlob:
    '{"Data": "another","Links": [{"Name": "some link","Hash": "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V","Size": 8}]}',
});

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.object.put({
  fileStringOrBlob:
    '{"Data": "another","Links": [{"Name": "some link","Hash": "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V","Size": 8}]}',
});

console.log(response);

pin

pin_add

Pin objects to local storage.

Request params

arg [Required] - Path to object(s) to be pinned.

recursive [Optional] - Recursively pin the object linked to by the specified object(s). Default: “true”

progress [Optional] - Show progress.

export interface IPinAddRequest {
  /**
   * Path to object(s) to be pinned.
   */
  arg: string;
  /**
   * Recursively pin the object linked to by the specified object(s). Default: “true”
   */
  recursive?: boolean | undefined;
  /**
   * Show progress.
   */
  progress?: boolean | undefined;
}
Response
Promise<IPinAddResponse>
export interface IPinAddResponse {
  /**
   * An array of Pin hashes
   */
  Pins: string[];
}
JavaScript/TypeScript
import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.pin.add(
  'QmSTkR1kkqMuGEeBS49dxVJjgHRMH6cUYa7D3tcHDQ3ea3',
);

console.log(response);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.pin.add(
  'QmSTkR1kkqMuGEeBS49dxVJjgHRMH6cUYa7D3tcHDQ3ea3',
);

console.log(response);

version

Show IPFS version information.

Request params

number [optional] - Only show the version number. Default is false

commit [optional] - Show the commit hash. Default is false

repo [optional] - Show repo version. Default is false

all [optional] - Show all version information. Default is false

export interface IVersionRequest {
  /**
   *  Only show the version number. Default is false
   */
  number?: boolean | undefined;
  /**
   * Show the commit hash. Default is false
   */
  commit?: boolean | undefined;
  /**
   * Show repo version. Default is false
   */
  repo?: boolean | undefined;
  /**
   * Show all version information. Default is false
   */
  all?: boolean | undefined;
}

Response

Promise<IVersionResponse>
export interface IVersionResponse {
  /**
   * Current version number
   */
  Version: string;
  /**
   * Current commit id
   */
  Commit: string;
  /**
   * Version number of the repo
   */
  Repo: string;
  /**
   * System information
   */
  System: string;
  /**
   * GoLang runtime version
   */
  Golang: string;
}

JavaScript/TypeScript

import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.version();

console.log(response);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.version();

console.log(response);

add

Add a file or directory to IPFS.

Request params

fileStringOrBlob [Required] - The file string or blob data

recursive [Optional] - Add directory paths recursively. Default: “false”.

quiet [Optional] - Write minimal output.

quieter [Optional] - Write only final hash.

silent [Optional] - Write no output.

progress [Optional] - Stream progress data.

trickle [Optional] - Use trickle-dag format for dag generation.

only-hash [Optional] - Only chunk and hash - do not write to disk.

wrap-with-directory [Optional] - Wrap files with a directory object.

hidden [Optional] - Include files that are hidden. Only takes effect on recursive add. chunker [string]: Chunking algorithm to use.

pin [Optional] - Pin this object when adding. Default: “true”.

raw-leaves [Optional] - Use raw blocks for leaf nodes. (experimental).

nocopy [Optional] - Add the file using filestore. (experimental).

fscache [Optional] - Check the filestore for pre-existing blocks. (experimental).

cid-version [int]: Cid version. Non-zero value will change default of ‘raw-leaves’ to true. (experimental). Default: “0”.

hash [string]: Hash function to use. Will set Cid version to 1 if used. (experimental). Default: “sha2-256”.

export interface IAddPutRequest {
  /**
   * The file string or blob data
   */
  fileStringOrBlob: string | Blob;
  /**
   * Add directory paths recursively. Default: “false”.
   */
  recursive?: boolean | undefined;
  /**
   * Write minimal output.
   */
  quiet?: boolean | undefined;
  /**
   * Write only final hash.
   */
  quieter?: boolean | undefined;
  /**
   * Write no output.
   */
  silent?: boolean | undefined;
  /**
   * Stream progress data.
   */
  progress?: boolean | undefined;
  /**
   * Use trickle-dag format for dag generation.
   */
  trickle?: boolean | undefined;
  /**
   * Only chunk and hash - do not write to disk.
   */
  onlyHash?: boolean | undefined;
  /**
   * Wrap files with a directory object.
   */
  wrapWithDirectory?: boolean | undefined;
  /**
   *  Include files that are hidden. Only takes effect on recursive add. chunker [string]: Chunking algorithm to use.
   */
  hidden?: boolean | undefined;
  /**
   * Pin this object when adding. Default: “true”.
   */
  pin?: boolean | undefined;
  /**
   * Use raw blocks for leaf nodes. (experimental).
   */
  rawLeaves?: boolean | undefined;
  /**
   * Add the file using filestore. (experimental).
   */
  nocopy?: boolean | undefined;
  /**
   * Check the filestore for pre-existing blocks. (experimental).
   */
  fscache?: boolean | undefined;
  /**
   * Cid version. Non-zero value will change default of ‘raw-leaves’ to true. (experimental). Default: “0”.
   */
  cidVersion?: number | undefined;
  /**
   * Hash function to use. Will set Cid version to 1 if used. (experimental). Default: “sha2-256”.
   */
  hash?: MultihashTypes | undefined;
}

export enum MultihashTypes {
  sha1 = 'sha1',
  sha2_256 = 'sha2-256',
  sha2_512 = 'sha2-512',
  sha3 = 'sha3',
  sha3_224 = 'sha3-224',
  sha3_256 = 'sha3-256',
  sha3_384 = 'sha3-384',
  sha3_512 = 'sha3-512',
  dbl_sha2_256 = 'dbl-sha2-256',
  // infura dont support this right now
  murmur3_128 = 'murmur3-128',
  // not implemented by infura
  keccak_224 = 'keccak-224',
  // not implemented by infura
  keccak_226 = 'keccak-226',
  // not implemented by infura
  keccak_384 = 'keccak-384',
  keccak_512 = 'keccak-512',
  shake_128 = 'shake-128',
  shake_256 = 'shake-256',
  // not implemented by infura
  x11 = 'x11',
  md5 = 'md5',
}

Response

Promise<IAddPutResponse>
export interface IAddPutResponse {
  /**
   * Name of the object
   */
  Name: string;
  /**
   * Hash of the uploaded object
   */
  Hash: string;
  /**
   * integer indication size in bytes
   */
  Size: string;
}

JavaScript/TypeScript

import { TerminalIpfsClient, SourceType } from '@terminal-packages/sdk';

const client = new TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
});

const response = await client.add({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);

Node

const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const client = new sdk.TerminalIpfsClient({
  uri: 'https://ipfs.infura.io:5001/api/v0/',
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: sdk.SourceType.Terminal,
});

const response = await client.add({
  fileStringOrBlob: '{"data": { "test": true }}',
});

console.log(response);

Apollo GraphQL

https://www.apollographql.com/

TerminalApolloLink

Using ApolloLink you can our sdk along with your Apollo client to log your GraphQL queries, you just need to setup our TerminalApolloLink

Basic options

export enum SourceType {
  Terminal = 'Terminal',
  Truffle = 'Truffle',
  Alchemy = 'Alchemy',
  MetaMask = 'MetaMask',
  Infura = 'Infura',
  Pocket = 'Pocket',
  Ledger = 'Ledger',
  Web3ProviderEngine = 'Web3ProviderEngine',
  WalletLink = 'WalletLink',
  TruffleHDWalletProvider = 'TruffleHDWalletProvider',
  Portis = 'Portis',
  QuikNode = 'QuikNode',
}
JavaScript/TypeScript
import {
  ApolloClient,
} from 'apollo-boost';
import {
  TerminalApolloLink,
  SourceType,
} from '@terminal-packages/sdk';

const client = new ApolloClient({
  link: new TerminalApolloLink({
    apiKey: 'yourApiKey',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    uri: 'yourgraphql.url/graphql',
  }),
  schema: {...}
})
Node
const { TerminalApolloLink } = require('@terminal-packages/sdk');
const { ApolloClient } = require('apollo-boost');

const client = new ApolloClient({
  link: new TerminalApolloLink({
    apiKey: 'yourApiKey',
    projectId: 'YOUR_TERMINAL_PROJECT_ID',
    // source can be a dynamic string as well
    source: SourceType.Terminal,
    uri: 'yourgraphql.url/graphql',
  }),
  schema: {...}
})

Composing Links

You can use ApolloLink method from to combine your current links to ours, creating one single link.

JavaScript/TypeScript
import {
  ApolloClient,
  ApolloLink
  HttpLink,
} from 'apollo-boost';
import {
  TerminalApolloLink,
  SourceType,
} from '@terminal-packages/sdk';

const client = new ApolloClient({
  link: ApolloLink.from([
    new TerminalApolloLink({
      apiKey: 'yourApiKey',
      projectId: 'YOUR_TERMINAL_PROJECT_ID',
      // source can be a dynamic string as well
      source: SourceType.Terminal,
      uri: 'yourgraphql.url/graphql',
    }),
    new HttpLink({ uri: 'yourgraphql.url/graphql' }),
  ]),
  schema: {...}
})
Node
const { TerminalApolloLink } = require('@terminal-packages/sdk');
const { ApolloClient, ApolloClient, HttpLink } = require('apollo-boost');

const client = new ApolloClient({
  link: ApolloLink.from([
    new TerminalApolloLink({
      apiKey: 'yourApiKey',
      projectId: 'YOUR_TERMINAL_PROJECT_ID',
      // source can be a dynamic string as well
      source: SourceType.Terminal,
      uri: 'yourgraphql.url/graphql',
    }),
    new HttpLink({ uri: 'yourgraphql.url/graphql' }),
  ]),
  schema: {...}
})

Package Sidebar

Install

npm i @terminal-packages/sdk

Weekly Downloads

55

Version

1.1.7

License

MIT

Unpacked Size

462 kB

Total Files

234

Last publish

Collaborators

  • terminalsystemsinc
  • joshstevens19
  • terminal-co
  • samuelea