synechron-finlabs / quorum-maker

Utility to create and monitor Quorum nodes
Apache License 2.0
196 stars 97 forks source link

web3.js connection problem #51

Open xuyangm opened 6 years ago

xuyangm commented 6 years ago

I built a 3-node TestNetwork by quorum-maker. And I deployed a very simple contract on it. Then I new a web3.js project to interact with the blockchain. The code is as below:

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new Web3.providers.WebsocketProvider('http://10.50.0.2:22005'));
console.log(web3.currentProvider);

var abi = [{"constant":false,"inputs":[],"name":"myFunction","outputs":[{"name":"myNumber","type":"uint256"},{"name":"myString","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"}];
var addr = "0x146291dac7a37966886d8d8b70a074c6b9fb2198";

var myContract = new web3.eth.Contract(abi, addr);
console.log(myContract.methods.myFunction().call());

And the execution result is as below:

root@mxy-VM:/home/mxy/web3test# node index.js 
WebsocketProvider {
  responseCallbacks: {},
  notificationCallbacks:
   [ [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification],
     [Function: requestManagerNotification] ],
  _customTimeout: undefined,
  connection:
   W3CWebSocket {
     _listeners: {},
     addEventListener: [Function: _addEventListener],
     removeEventListener: [Function: _removeEventListener],
     dispatchEvent: [Function: _dispatchEvent],
     _url: 'http://10.50.0.2:22005',
     _readyState: 0,
     _protocol: undefined,
     _extensions: '',
     _bufferedAmount: 0,
     _binaryType: 'arraybuffer',
     _connection: undefined,
     _client:
      WebSocketClient {
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        config: [Object],
        _req: [ClientRequest],
        protocols: [],
        origin: undefined,
        url: [Url],
        secure: false,
        base64nonce: 'Qw0wxEadUJGRZIggxR1AvQ==' },
     onerror: [Function],
     onclose: [Function],
     onmessage: [Function] },
  connected: [Getter] }
Promise { <pending> }

It seems that blockchain is not connected? What's wrong with my operation?

rjbanner commented 6 years ago

@mageover could you specify the OS you're using?

xuyangm commented 6 years ago

@rjbanner OS is ubuntu 16.04

rjbanner commented 6 years ago

@mageover Could you try building a regular 3 node network using quorum-maker (by choosing option 1 first to create the first network node and then option 2 twice to create the other 2 nodes) and then checking whether the same issue persists?

weiliin commented 5 years ago

The web3.js version you use is 1, so the result is Promise. I suggest you take a look at this document https://web3js.readthedocs.io/en/1.0/getting-started.html

dhyansraj commented 5 years ago

Can you check this again? A pull request for WS related fix is merged in latest release.