Watch pending transactions on Ethereum using ethersjs
* script.js
const ethers = require('ethers');

const apiKey = { projectId: process.env.INFRA_PROJECT_ID };
const provider = new ethers.providers.InfuraWebSocketProvider('homestead', apiKey);

async function main() {
.on('pending', pendingTransaction=> {
console.log(`new pending transaction received. ${pendingTransaction}`);
// do whatever you like.
.catch(err => {


  1. Node.js Environment
  2. following dependencies
    a. ethersjs
    b. dotenv
  3. Infra Account & your Infra project ID


// create your own project directory
$ mkdir yourproject
// initialize npm and install dependencies
$ npm init -y && npm install ethers dotenv
// create your own javascript file and paste the snippet above
$ touch script.js
// create .env file and paste your infra project id as INFRA_PROJECT_ID
$ touch .env



interested in crypto and art

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Alfred to Roam

Adding Validators to Reactive Form

Random Creations : Week 1 — Android Random List App + 3D Renders

Make API Calls the Right Way in Angular

Migrating from JavaScript to TypeScript (from scratch)

What the THUNK? Using and understanding Thunk in your React/Redux app.

How to Improve LCP and Speed Index for Next.js Websites

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hiroyuki Tachibana

Hiroyuki Tachibana

interested in crypto and art

More from Medium

Signing Transactions With React, Permit Transactions EIPS712

The Tatum C# SDK is now live!

Accessing a smart contract on Ethereum Network

Laika Blockchain Lab (5 Jan 2022 Update)