Web3.js Uncaught TypeError: net.connect не является функцией - PullRequest
0 голосов
/ 26 августа 2018

Я могу запустить приведенный ниже код, используя JavaScript успешно из командной строки: -

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' ]

Я использовал тот же код вactjs, когда я запускаю npm, я получаю сообщение об ошибке. Почему-то кажется, что соединение IPC не работает. Я был бы очень признателен, если кто-то может помочь мне в этом.

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);

Ошибка из 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

`

...