web3.js
version: 1.0.0-beta.24
I want to listen all ether transaction events and then write them into database once transferred value is bigger than 0. I went multiple times though the (documentation)[https://web3js.readthedocs.io/en/1.0/web3-eth.html#id56]. Can you point me the a page or tell where can I find any info about that?
Ok, I think the answer was this one
web3.eth.subscribe('pendingTransactions', function(error, result){})
.on("data", function(trxData){
web3.eth.getTransaction(trxData).then(console.log);
});
Got confused due to #1144
This doesn't seem to work for me using geth 1.7.2 stable version. I get the following error after running this via node
connection not open on send()
My script is
var Web3 = require('web3')
var web3 = new Web3("ws://localhost:9546") // don't worry port is correctly set
web3.eth.subscribe('pendingTransactions', function(error, result){}) .on("data", function(trxData){ web3.eth.getTransaction(trxData).then(console.log); });
how did you get it to work @kot-begemot ?
@raahil190 you might be missing core cors for ws port. Here is how I start my client
# go client
geth --datadir /PATH_TO_STORAGE --testnet --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --ws --wsport 8585 --wsorigins="*"
# parity client
parity --port=30304 --jsonrpc-port=8546 --jsonrpc-interface=127.0.0.1 --ws-port=8586 --ws-origins="*" --chain=ropsten --base-path=/PATH_TO_STORAGE
@kot-begemot I can't seem to get it to work without the
--wsorigins "*" flag , that should make it pretty insecure I guess - or is there a way around it ?
@raahil190 Depends on your setup. Do you plan to make it available to whole internet?
No - I plan to use it myself only. But if I don't use --wsorigins "*" it does not work @kot-begemot
Maybe same error, when I start geth in docker. Without "--wsorigins *", I got connection not open on send() in my client. Add the cmd line args, it works.
Most helpful comment
@kot-begemot I can't seem to get it to work without the
--wsorigins "*"flag , that should make it pretty insecure I guess - or is there a way around it ?