0

I'm totally new to Ethereum, and want to create some deposit address monitoring system using web socket. Which gets newly generated blocks and scan it for transactions made into it. You can find code here: https://github.com/AlanL1/Ethereum-FrontEnd

But geth is not connected with application. I have already installed geth

enter image description here

Am i missing something?

  • Is metamask installed, if yes, you can select metamask network "localhost 8545" from metamask dropdown. metamask itself injects web3 instance, you should create new instance like 'web3js' with window.web3js = new Web3(web3.currentProvider); – kherwa May 14 '18 at 10:42
  • If I select local host from dropdown, it just stuck with Connecting to Unknown Private Network – Hina Khuman May 14 '18 at 11:04
  • start geth with "geth --testnet --rpc --rpccorsdomain="*" – kherwa May 14 '18 at 11:07
  • Fatal: Error starting protocol stack: listen udp :30303: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted – Hina Khuman May 14 '18 at 11:08
  • you must have already running geth – kherwa May 14 '18 at 11:09
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.io/<API KEy>'
         window.web3js = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
     }

here you can see i have added web3js instance, instead of replacing web3 instance injected by Metamask or Mist.

Update

To consume JSON-RPC API's over WebSockets, use web3.js beta version 1.0.0-beta https://github.com/ethereum/web3.js/tree/1.0

First expose RPC API's over Web Socket Interface

geth --testnet --ws --wsorigins="*"

then instantiate web3 in your page as

web3 = new Web3("ws://127.0.0.1:8546");   

Written a detailed blog on setting up local geth node & communicating with it. http://blog.kherwa.com/2018/05/10/building-a-dapp-series-part1-set-up-and-communicate-with-an-ethereum-node/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.