How to listen to Smart Contract Events with Web3.js
3 min readMay 3, 2021
a beginners guide…
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)
- clone the repo (git clone https://github.com/fkochan/whale_sightseeing)
- 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)
- finally in your terminal run: npm install
- 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