18

At a guess, it's because of this: --wsorigins value Origins from which to accept websockets requests I encountered the same 403 error, added --wsorigins="*", and was able to connect. Please note that for security reasons you most likely do NOT want to allow * but instead be more explicit.


5

was fixed on web3@1.0.0-beta.36 https://github.com/ethereum/web3.js/issues/1559#issuecomment-412348642


4

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('newBlockHeaders', (error, blockHeader) => { if (error) return console.error(error); console.log('Successfully subscribed!', blockHeader); }).on('data', (...


3

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 indexed player1, address indexed player2); event PlayerMoved(bytes32 indexed gameId, address indexed player); event GameEnded(bytes32 indexed gameId, address indexed ...


3

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 web3@1.0.0-beta.34 https://github.com/ethereum/web3.js/issues/1559 I confirmed web3@1.0.0-beta.35 has not fixed the issue yet in my environment. So downgrading ...


3

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 --ws --wsorigins <...>. If the host field is empty, specify the Origin header inside WebsocketProvider's options like: const wsProvider = new Web3....


2

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: const web3 = new Web3('ws://localhost:8546') const provider = web3.providers.WebsocketProvider const { connection } = provider At this point, the connection ...


2

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


2

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 subscription type newHeads, and scan through all the new blocks using getTransactionFromBlock. The performance is okay since I am not polling and only react if a new block ...


2

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 = 'yourContractAddress'; const contract = new web3.eth.Contract(abi, address); contract.getPastEvents('allEvents', { fromBlock: 0, toBlock: 'latest' }).then(...


1

About 1. for creating fresh addresses you can use keythereum or ethers.js. Take a look on both libraries and pick the one you prefer. About 2. and 3. To track the payments I see 2 options: You will be using nodejs so you can setup nodejs cronjob and check in block range ({fromBlock: X, toBlock: 'latest'}) the new transactions that sent ethers to your main ...


1

Please check whether your Geth node is completely synced


1

According to this, the web3 provider URL should look something like: wss://ropsten.infura.io/ws/v3/YOUR-PROJECT-ID


1

web3.eth.getBalance(address) returns a promise which will only either return an error or the balance once the transaction is mined. function getBalance(){ var balance; web3.eth.getBalance(address, (err, bal) => { balance = bal }) return balance; } the case above will return undefined because the function already returned the balance before the ...


1

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 ::


1

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(HumanFriendlyToken).forEach((contract) => { contract.setProvider(provider) if (typeof contract.currentProvider.sendAsync !== "function") { ...


1

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 default.


1

Try this : geth --ws --wsaddr "0.0.0.0" --wsapi "eth,net,web3,admin,shh" --wsorigins "*" --mine --minerthreads=1 --datadir ./test/testDataDir/ --networkid 15


1

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 similar) query, the blocks will be local and therefore much faster. We're working on a wrapper for QuickBlocks to be callable from node.js, but that's not ready ...


1

you can use this sample code: if(type of web3 !== 'undefined'){ // Use injected web3 by Metamask/Mist window.web3js = new Web3(web3.currentProvider); } else { // Fallback to local node // you can use Infura Node Urls also // 'http://127.0.0.1:8545' will be replaced by // 'https://ropsten.infura....


1

REST API, you would have to poll for data periodically and make changes for every poll you do. Websockets allow you to essentially listen for changes and make changes on your end accordingly based on whatever changed, almost instantly. They both have their advantages and disadvantages. REST polling allows you to cache data in a much easier fashion, which ...


1

Check if the page is accessible first. Sometimes the page itself may be down, happened for me with Ropsten


1

You may use a reactPHP based process to react on your contract events. Do I need own rpc node? -> No it would work with a service like infura.io Do I need websocket - endpoint? -> No. Using http provider. Must I send requests to the EVM everytime or how can I get every raised event from my contract? -> Kind of, but the ethereum-php-eventlistener would do ...


1

Where is the source code for this, given it's nowhere to be found in github.com/ethereum/web3.js https://github.com/HaoLLL/web3-eth-contract/blob/master/src/index.js


1

Basically, it's required to declare the option --wsorigins "*" in the geth command in order to connect to the nodes via websocket provider or http provider. In your case, you are missing double dash in front of syncmode, adding double dash or remove syncmode solves the problem. Additional, according to the article https://github.com/ethereum/go-ethereum/...


1

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.


1

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:8546');


1

I assume that you're using a version of Web3.js older than 1.0. I believe that the WebsocketProvider was added in 1.0.


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