Skip to main content
38 votes
Accepted

How to listen to contract events using ethers.js?

This answer assumes that you understand how to connect to a contract using Ethers. Your question specifies listening for an event to be emitted, and to do a task based on that. Here is the link to the ...
The Renaissance's user avatar
26 votes

How to listen to contract events using ethers.js?

// event in ERC-20: Transfer(address indexed src, address indexed dst, uint val) contract.on("Transfer", (to, amount, from) => { console.log(to, amount, from); }); You ...
Vanja Dev's user avatar
  • 871
24 votes
Accepted

Geth can't connected to via Websocket

At a guess, it's because of this: --ws.origins value Origins from which to accept websockets requests I encountered the same 403 error, added --ws.origins="*", and was able to connect. ...
Dan Turner's user avatar
7 votes

Geth can't connected to via Websocket

Below is an answer for errors when connecting from web3.js WebsocketProvider. Short Answer If there is client's host noted inside origin '<...>' in message, just specify it with geth as geth --...
viz's user avatar
  • 535
5 votes

web3 Websocket connection to infura

was fixed on [email protected] https://github.com/ethereum/web3.js/issues/1559#issuecomment-412348642
Ernane Luis's user avatar
5 votes
Accepted

How to apply EthFilter to specific address?

OK, let's say you have a smart contract deployed on the address CONTRACT_ADDRESS which can trigger different type of events Event definitions: event GameStarted(bytes32 indexed gameId, address ...
Greg Jeanmart's user avatar
5 votes
Accepted

Is there a way to listen to log events via websocket with web3py

Web3.py doesn't offer methods to subscribe automatically so we have to manually listen to the websocket and use rpc methods to send the subscription to logs : import asyncio import json from web3 ...
Kaki Master Of Time's user avatar
5 votes
Accepted

Reading and listening to Solidity events via Web3.py and websocket

One way to get around the constant HTTP calling is using websocket which is capable of listening to events on the network without making any API calls. I will show it in the code bellow how to achieve ...
f22daniel's user avatar
  • 373
4 votes

web3 Websocket connection to infura

This is working #!/usr/bin/env node const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws')); const subscription = web3.eth.subscribe('...
Daniel Luca CleanUnicorn's user avatar
4 votes

Ganache and webscockets

Yes, you can connect with websocket by using the RPC url, but replacing http:// with ws://. In my case (and the default), it is: ws://127.0.0.1:7545 Example code using ethers.js: const provider = new ...
larskarbo's user avatar
  • 196
3 votes

web3 Websocket connection to infura

It seems a value of WebSocket request header is invalid. More specifically say, a value of Sec-WebSocket-Protocol is undefined. According to the github issue below, the issue was introduced from ...
sushiether's user avatar
3 votes
Accepted

Is there a max number of websocket connections that geth can support?

1 million, or maybe 2 million, all depends on your hardware. This is not a question about Ethereum , but more about: golang.org/x/net/websocket which is what go-ethereum uses
Nulik's user avatar
  • 4,061
3 votes

How to connect with WebSocket with Web3?

I think this is what you are looking for: const Web3 = require('web3'); const web3 = new Web3('wss://ropsten.infura.io/ws/v3/<yourID>'); const abi = "placeYourABI"; const address = '...
cqx's user avatar
  • 3,462
2 votes

TypeError: Web3.providers.WebsocketProvider is not a constructor?

you need to wrap Web3 object inside {} const {Web3} = require('web3')
Nisarg's user avatar
  • 21
2 votes

TypeError: Web3.providers.WebsocketProvider is not a constructor?

I had the same issue with web3 v1.0.0 beta 30. Never got to the bottom of it but skipping the provider construction appeared to fix it: var Web3=require('web3'); var web3 = new Web3('ws://10.244.5.43:...
Linmao Song's user avatar
  • 2,357
2 votes

How to expose the underlying web socket connection from the WebSocketProvider?

Let me answer each of your questions: 1. At what point is the connection actually made The connection is actually made after creating a WebsocketProvider object. Taking a snippet from your example: ...
perfectmak's user avatar
2 votes

web3 websocket connection prevents node process from exiting

WebSockets provide a persistent connection between a client and server. This connection has to be manually closed, otherwise the library tries to keep the connection alive. It feels funny to me ...
Daniel Luca CleanUnicorn's user avatar
2 votes

Is there any websocket ethereum provider?

You can use Bitquery streams. Get real-time balance updates on ethereum - https://ide.bitquery.io/Get-real-time-balance-updates-on-ethereum subscribe to UDST Token Transfers on Ethereum - https://ide....
Gaurav Agrawal's user avatar
2 votes
Accepted

Is there any websocket ethereum provider?

Use Infura.io to connect to different blockchains. You will need an account and project id. Steps to create an Infura.io Project and remarks 1) Open Infura.io page and sign up for an account. On ...
Markus Sprunck's user avatar
2 votes

Subscription using websocket through Geth

Eventually, I developed a proof-of-concept. I posted the source in GitHub at https://github.com/AlanL1/Ethereum-FrontEnd The code that might be useful to you is in transaction.html. I use ...
user8740106's user avatar
2 votes
Accepted

connecting geth to web3.js 1.0 via websockets or HTTP

There is a typo in geth command line: you miss double dash in front of syncmode. Not sure why, but it seems to prevent geth from launching HTTP RPC listener.
abb's user avatar
  • 466
2 votes

Subscribe to events using local geth in light mode?

No, my suggestion was wrong, the problem is different. I did the same steps, but with web3.js and it worked out. UPD: So, after updating the go package go-ethereum to v1.9.2, everything works ...
Ivan Zakharov's user avatar
2 votes

Is there a websocket URL in Ethereum classic like in Ethereum?

Short answer: no idea. It's not a functionality of the blockchain protocol. It's a functionality in the client nodes. So the Ethereum itself doesn't care how people interact with it, as long as the ...
Lauri Peltonen's user avatar
2 votes

405 Method Not Allowed with websocket geth RPC

OK, the issue is that several guides on how to connect to websockets using Curl don't work on geth's websocket for whatever reason. Using a tool specifically for websockets allowed the requests to go ...
Dobit's user avatar
  • 162
1 vote

What is the safest way to use WS-RPC server in geth?

As a general rule of thumb, any open port is a security risk. The best way to prevent an attack by malicious actor would be to have no doors and no windows. Specifically, in blockchain nodes, the risk ...
Kof's user avatar
  • 2,964
1 vote

Connecting to blockchain on azure using web3.js and websocket

If you are using azure POA consortium you have already a websocket endpoint. The url is available under deploiment outputs as shown in the picture below ::
Badr Bellaj's user avatar
  • 18.8k
1 vote
Accepted

TypeError: Cannot set property 'method' of undefined when using WebsocketProvider

Make sure you have ganache-cli@beta installed You have to hack around the send and sendAsync issue when setting provider. so: export const setProvider = (provider: any) => Contracts.concat(...
GoingOutW3st's user avatar
1 vote

TypeError: Cannot set property 'method' of undefined when using WebsocketProvider

Are you aware that the API for RPC and WS is different? Not sure if ganache supports this, with the "normal" geth you need to start it like geth --ws. That will bind the websocket API to port 8546 per ...
leberknecht's user avatar
1 vote

"Connection not open" error when subscribing to address with websocket

Try this : geth --ws --wsaddr "0.0.0.0" --wsapi "eth,net,web3,admin,shh" --wsorigins "*" --mine --minerthreads=1 --datadir ./test/testDataDir/ --networkid 15
Archi's user avatar
  • 379
1 vote

Get a large amount of blocks with web3 (nodejs)

Sorry for the self-promotion, but you can use QuickBlocks to do the same thing much more effectively because it will additionally cache the blocks locally so that the next time you do the same (or ...
Thomas Jay Rush's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible