How to listen to Smart Contract Events with Web3.js

Ferhat Kochan
3 min readMay 3, 2021

a beginners guide…

whale hello there…

It’s been awhile but i’m glad i got the patience to write another one of these.

The guide below gets you started with listening to past events from a smart contract.You can interact with smart contracts using the popular package Web3js. To run the project it’s fairly easy as long as you have npm installed and have a working ethereum or matic rpc url (if you don’t get one from QuikNode.io, or Infura.io)

  1. clone the repo (git clone https://github.com/fkochan/whale_sightseeing)
  2. create an .env file (i.e. nano .env) then in the .env file, create a variable called NODE_URL then set the value as your web3 provider (i.e. NODE_URL=RPC_URL)
  3. finally in your terminal run: npm install
  4. then run: npm start!

After you should see some information output in your terminal. Now let’s dive into the technical side ;)

Line 1–2: imports web3 and dotenv modules

--

--