Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@terminal-packages/sdk

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@terminal-packages/sdk

Ethereum developer tool kit for the Terminal platform

  • 1.0.24
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by247.06%
Maintainers
3
Weekly downloads
 
Created
Source

npm version downloads Twitter Follow Discord Channel

Terminal-logo

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

TerminalSDK - Logging for Blockchain Infrastructure

Terminal is an developers platform for builing on Ethereum. Develop, test, and manage Ethereum artifacts and infrastructure in a unified workspace with Terminal. The Terminal toolkit provides developers with a broad range of utilities to construct robust and user-friendly decentralized applications or dapps.

TerminalSDK allows you to surface logs from arbitrary RPC endpoints and networks 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 fetch logs for any RPC endpoint
  • Surface logs for injected web3 providers
  • Introduce cloud logging into your Truffle development environment
  • Compatible with web3.js and ethers.js

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

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalHttpProvider({
    host: 'https://yourethnodeurl.io',
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    customHttpProvider: new YourCustomHttpProvider()
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalHttpProvider({
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);
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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    customHttpProvider: new YourCustomHttpProvider()
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const provider = new ethers.providers.Web3Provider(
  new sdk.TerminalHttpProvider({
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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'
}

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalWebsocketProvider({
    host: 'wss://yourethnodeurl.io',
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    customWebsocketProvider: new YourCustomWebsocketProvider()
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const Web3 = require('web3');

const web3 = new Web3(
  new sdk.TerminalWebsocketProvider({
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);
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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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
  })
);

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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    // 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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    customWebsocketProvider: new YourCustomWebsocketProvider()
  })
);
Node
const sdk = require('@terminal-packages/sdk');
const ethers = require('ethers');

const web3 = new ethers.providers.Web3Provider(
  new sdk.TerminalWebsocketProvider({
    apiKey: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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: 'yourApiKey',
    // projectId is not required to log but we suggest
    // using it for the best experience
    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,
    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'});
  </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"></script>

Keywords

FAQs

Package last updated on 29 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc