Integrating QuikNode Provider Endpoints with Terminal

Today, we will go through integrating your QuikNode endpoint with the TerminalSDK. If you are a dApp developer then you probably know retrieving dApp-specific logging and infrastructure analytics is one of the most important parts of the development process, but can also be the most difficult.

We'll be walking through how to surface all logs from a QuikNode endpoint into Terminal, a monitoring platform for your blockchain application. QuikNode is a powerful web3 infrastructure provider that offers private nodes to ensure maximum security and speed for your dApp.

To begin, we will assume that you have a QuikNode endpoint. If not you can checkout the website here to get one. Once you have a QuikNode endpoint integrated with a basic dApp, surfacing logs with the TerminalSDK is easy and straightforward. In this tutorial, you’ll see how to build a simple dApp to make basic Web3 calls and surface the logs.

For this tutorial we’re going to use a simple JavaScript file that retrieves the balance of an address as well as the transaction details of a transaction. We chose the address and transaction arbitrarily from Etherscan. The full code for the script is available at the bottom of the page.

Feel free to substitute in any Web3 methods here. QuikNode supports all the standard web3 RPC methods, as well as Geth and Parity specific modules (eg. debug, txpool, pendingTransactions & parity_).

Below is a sample of what your code might look like before wrapping the TerminalSDK:

const Web3 = require("web3");
 
const web3 = new Web3(
  new Web3.providers.HttpProvider(
     // your quiknode endpoint
    "https://newly-relaxed-grackle.quiknode.io/hash/hash/" 
  )
);
const address = "0xab7c74abC0C4d48d1bdad5DCB26153FC8780f83E";
 
web3.eth.getBalance(address, (err, wei) => {
  balance = web3.utils.fromWei(wei, "ether");
  console.log(balance.toString(10));
});
 
const tx = "0x4b35d880f099fb8ad9a00846699c868bf1de1fe045bd68491f2c92b891571d58";
 
web3.eth.getTransaction(tx, (error, result) => {
  console.log(error);
  console.log(result);
});

In your Javascript project, your Web3 instance probably looks similar to the above code. In order to surface logs to your Terminal account, you will simply need to wrap the Web3 instance with the TerminalSDK. Beforehand, your QuikNode endpoint is passed in to the creation of the Web3 instance like this:

import Web3 from 'web3';

const web3=new Web3(new Web3.providers.HttpProvider("QUIKNODE_ENDPOINT"));

The first step is to signup for a Terminal account here. You will need to generate an API key as well as create a new project and find the projectId. You can find instructions on how to do so here.

Once your account is created install the Terminal SDK with the following command:

npm install @terminal-packages/sdk

Now that you have the TerminalSDK installed, wrap your web3 initialization like this:

const Web3 = require("web3");
const {
  TerminalHttpProvider,
  SourceType
} = require("@terminal-packages/sdk");
 
const web3 = new Web3(
  new TerminalHttpProvider({
    host: "YOUR_QUIKNODE_ENDPOINT",
    apiKey: "YOUR_TERMINAL_API_KEY",
    projectId: "YOUR_TERMINAL_PROJECTID",
    source: SourceType.Quiknode // source can be a string as well
  })
);

Once you’ve done this, you can simply run the script from your command line using node.js. As soon as you run the script, the logs will get pushed to your Terminal Logging Platform and look something like this:

Now that you are receiving logs directly to your Terminal account, you can sort through your logs using an array of different filters. This makes finding whatever you’re looking for as easy as possible. If you're having trouble getting this to work, please feel free to message the Terminal Support team for help in the discord or on the Terminal.co website using the message icon in the bottom right.

If your project uses other infrastructure or wallet providers, the logs will be surfaceable as well. Terminal Logs offers a host of other logging and analytics services to accommodate all of your Web3 needs:

  • Surface logs from RPC endpoints like QuikNode.
  • Surface logs from any injected Web3 wallet providers such as MetaMask
  • Introduce cloud logging into your Truffle development environment
  • Compatible with web3.js and ethers.js
  • Filter logs by type, source, timestamp, and others
  • Live application and user analytics for your dapp

Check out the docs for information on further use of TerminalSDK!

Below is the full code for the project. Paste in your corresponding endpoint and keys and you should be good to go.

const Web3 = require("web3");
const {
  TerminalHttpProvider,
  SourceType
} = require("@terminal-packages/sdk");
 
const web3 = new Web3(
  new TerminalHttpProvider({
    host: "YOUR_QUIKNODE_ENDPOINT",
    apiKey: "YOUR_TERMINAL_API_KEY",
    projectId: "YOUR_TERMINAL_PROJECTID",
    source: SourceType.Quiknode // source can be a string as well
  })
);
const address = "0xab7c74abC0C4d48d1bdad5DCB26153FC8780f83E";
 
web3.eth.getBalance(address, (err, wei) => {
  balance = web3.utils.fromWei(wei, "ether");
  console.log(balance.toString(10));
});
 
const tx = "0x4b35d880f099fb8ad9a00846699c868bf1de1fe045bd68491f2c92b891571d58";
 
web3.eth.getTransaction(tx, (error, result) => {
  console.log(error);
  console.log(result);
});

We hope that this integration provides useful insights and actionable data to help you develop a new Web3 dApp... or improve an existing one!