Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor server side: contract event.watch error #1333

Closed
ghost opened this issue Jan 29, 2018 · 4 comments
Closed

Meteor server side: contract event.watch error #1333

ghost opened this issue Jan 29, 2018 · 4 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jan 29, 2018

I can't watch for an event on the server side of my Meteor app. (client is working fine)

  • Ropsten testnet + Metamask.

I tried two alternatives:
A) using ethereum/web3 meteor package
Server side code:


 if (typeof web3 !== 'undefined') {
            web3 = new Web3(web3.currentProvider);
        } else {
            // set the provider you want from Web3.providers
            web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/"));
}

methods.js

var myContract= web3.eth.contract(ABI).at(ADDRESS);

myContract.myEvent().watch(function(error, result){
            if (!error)
                      console.log(result); 
              else console.error(error);
      });

error

I20180129-11:31:25.267(1)? Exception while invoking method 'addContract' TypeError: XHR2 is not a constructor
I20180129-11:31:25.274(1)?     at HttpProvider.prepareRequest (packages\ethereum_web3.js:4315:15)
I20180129-11:31:25.274(1)?     at HttpProvider.sendAsync (packages\ethereum_web3.js:4364:22)
I20180129-11:31:25.275(1)?     at RequestManager.sendAsync (packages\ethereum_web3.js:6369:19)
I20180129-11:31:25.276(1)?     at Object.send [as newFilter] (packages\ethereum_web3.js:5080:42)
I20180129-11:31:25.277(1)?     at new Filter (packages\ethereum_web3.js:3568:25)
I20180129-11:31:25.278(1)?     at SolidityEvent.execute (packages\ethereum_web3.js:3341:12)
I20180129-11:31:25.285(1)?     at DDPCommon.MethodInvocation.addContract (server/methods.js:172:35)
I20180129-11:31:25.285(1)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1768:12)
I20180129-11:31:25.286(1)?     at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20180129-11:31:25.287(1)?     at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1186:15)

B) using web3@0.20.1 npm package
(Removed ethereum/web3 package)

Server side code:

 import Web3 from 'web3'; //using web3@0.20.1

 if (typeof web3 !== 'undefined') {
            web3 = new Web3(web3.currentProvider);
        } else {
            // set the provider you want from Web3.providers
            web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/"));
}

methods.js

var myContract= web3.eth.contract(ABI).at(ADDRESS);

myContract.myEvent().watch(function(error, result){
            if (!error)
                      console.log(result); 
              else console.error(error);
      });

error

W20180129-10:41:57.150(1)? (STDERR) C:\Smart\node_modules\web3\lib\web3\filter.js:159
W20180129-10:41:57.152(1)? (STDERR)                 cb(error);
W20180129-10:41:57.153(1)? (STDERR)                 ^
W20180129-10:41:57.158(1)? (STDERR)
W20180129-10:41:57.159(1)? (STDERR) TypeError: cb is not a function

And finally, this is not an issue now, but it's kind of annoying that web3 (global) is defined on client side, but undefined on server side. That's "solved" using web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/")); but what if I wanna keep using the same instance as in the client side and get, for example, web3.eth.accounts on the server side?

Thanks!

@nivida nivida self-assigned this Aug 9, 2018
@robertdavid010
Copy link

robertdavid010 commented Oct 11, 2018

Hello all, have been working on this issue also for a while. Web3 is working in the Meteor client, but I have seen several open questions on SO relating to server side issues with Web3 in Meteor. I've collated them in a new SO . As far as I can tell, it seems like an unintentional package dependency recursion loop (have addressed same effect with another npm package in Meteor before).

Will attempt to determine which is the package conflict. Of important note, the effect (empty Web3 object {}) occurs in a new Meteor --bare project with only meteor npm install --save web3 cli command run on the project. Have also tried require() to the dist file (which throws a different error on server, but which you can fix by editing a line in the dist file), with the same result.

@robertdavid010
Copy link

robertdavid010 commented Oct 12, 2018

Update: @fedecryto @nivida @frozeman Having isolated the fact that there is a dependency recursive loop that is preventing web3 from being imported, I have tested removing most of the Meteor npm package dependencies from the core of the framework using meteor npm uninstall --save meteor-node-stubs. This removes most of the functionality of the framework for the client/server connection as it works out of the box. However the server can still run. After removing the above meteor npm package, the web3 library will be imported as expected into the server context. The next step will be isolating which specific package is causing the problem. The current hypothesis is that one of the embedded dependencies in the meteor-node-stubs package is in conflict with a web3 dependency, and process of elimination will indicate which is the specific culprit.

These are the dependencies in meteor-node-stubs.

@robertdavid010
Copy link

robertdavid010 commented Oct 15, 2018

Updated my SO with an answer which describes the 'workaround' to get Web3 working on the Meteor server.

NOTE: This relates to Web3 1.0

@nivida nivida added the support label Nov 29, 2018
@nivida
Copy link
Contributor

nivida commented Apr 16, 2019

Closed because of the ongoing clean up of the issue list. Feel free to ask this in our gitter channel or on stackoverflow.

@nivida nivida closed this as completed Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants