Ropsten infura test network + web3 js event listener

Ethereum Asked by Kapil on October 26, 2020

I have deployed contracts on ropsten test network.

ropsten: {
  provider: function() {  
    return new HDWalletProvider(mnemonic, "<api-token>")
  network_id: '*',


pragma solidity ^0.4.17;

contract SimpleStorage {
  uint myVariable;
  event emitval();

  function setValue(uint x) public {
    myVariable = x;

  function getValue() public returns (uint) {
    return myVariable;

In my node js code I am using web3 js to call/listen methods/events from contracts.

my node js file is

web3.setProvider(new Web3.providers.WebsocketProvider('<api-token>'));

and for listening events I wrote

var contracts = new web3.eth.Contract(importedjson.abi, deployedaddressat), result){
    if(error) { console.log(error);} 
    else { console.log('Event setVal:', result);}

When I am calling methods of solidity (setValue() or getValue() which emits emitval() event), I am not able to listen it on node js code.

Could you please help me out.
I am uisng latest web3js version “1.0.0-beta.33”.

2 Answers

Can you try replacing web3.setProvider(new Web3.providers.WebsocketProvider(''));


web3.setProvider(new Web3.providers.WebsocketProvider('wss://'));

It might be a websocket issue as web3 1.0 doesn't support events for http.

Answered by Ashish Mishra on October 26, 2020

I can't see such setVal events in your contract. Indeed, in the contract, the name is emitval. You can try to change your code, result){
    if(error) { console.log(error);} 
    else { console.log('Event setVal:', result);}

and alternative is to listen to all the contract events using ref

Answered by mirg on October 26, 2020

Add your own answers!

Related Questions

Avoiding double spending in Plasma Cash

1  Asked on December 25, 2021


Filter past events with condition

0  Asked on December 25, 2021 by simon-bachmann


fatal error when try to serve geth in ipc

1  Asked on December 23, 2021


How long did a transaction spend in the mempool?

1  Asked on December 22, 2021 by jespern


Migrate contract from testnet to mainnet

2  Asked on December 20, 2021


Is there some possibility to listen MakerDAO’s LogNote events?

1  Asked on December 20, 2021 by svitlana-moiseyenko


Call a smart contract function when condition met

1  Asked on December 18, 2021 by yohjinakamoto


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP