I am able to run below code using a javascript succesfully from a command line:-
var net = require('net');
var web3 = new Web3('~.ethereum/privatechain/node1/geth.ipc', net);
var version = web3.version;
console.log(version);
console.log("DEBUG: Start Executing Scxripts", version)
web3.eth.getAccounts(console.log);
$mesnia@linux:~ node interactWithNodes.js
Result:
1.0.0-beta.35
DEBUG: Start Executing Scxripts 1.0.0-beta.35
null [ '0x277F73CC484258ED27X9C8YF9A0c7dd12Ee0773b' ]
I used the same code in reactjs, when i do npm start I get an error. For some reason it seems like the IPC connection did not work. I would very much appreciate if someone can help me on this.
import React, { Component } from 'react';
import './style.css';
import Web3 from 'web3';
var net = require('net');
var web3 = new Web3(new Web3.providers.IpcProvider('/home/rjoshi/.ethereum/privatechain/node1/geth.ipc', net));
var version = web3.version;
console.log(version);
web3.eth.getAccounts(console.log);
console.log(web3.eth.coinbase);
Error from React: `
index.js:37 Uncaught TypeError: net.connect is not a function
at new IpcProvider (index.js:37)
at Object../src/components/Home/index.js (index.js:7)
at __webpack_require__ (bootstrap 769a623b2fe16b225c3f:678)
at fn (bootstrap 769a623b2fe16b225c3f:88)
at Object../src/components/App/index.js (immutable.js:19)
at __webpack_require__ (bootstrap 769a623b2fe16b225c3f:678)
at fn (bootstrap 769a623b2fe16b225c3f:88)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap 769a623b2fe16b225c3f:678)
at fn (bootstrap 769a623b2fe16b225c3f:88)
at Object.0 (registerServiceWorker.js:117)
at __webpack_require__ (bootstrap 769a623b2fe16b225c3f:678)
at ./node_modules/ansi-regex/index.js.module.exports (bootstrap 769a623b2fe16b225c3f:724)
at bootstrap 769a623b2fe16b225c3f:724
`