0

I am working on a uport dApp. uPort by default uses web3 from rinkeby.infura.io which is web3 version 0.19. So no WebSocket available. I tried ZeroClientProvider but that leads to this error:

Error in ./~/eth-block-tracker/src/index.js
Module parse failed: C:\Users\Rahul\Desktop\projUport\node_modules\eth-block-tracker\src\index.js Unexpected token (38:8)
Module parse failed: C:\Users\Rahul\Desktop\projUport\node_modules\eth-json-rpc-infura\src\index.js Unexpected token (25:54)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (25:54)
 @ ./~/eth-json-rpc-infura/src/createProvider.js 3:31-49

My code for it was:

const ProviderEngine = require('web3-provider-engine/index.js');
const ZeroClientProvider = require('web3-provider-engine/zero.js');
const engine = ZeroClientProvider({
  getAccounts: function(){},
  rpcUrl: "https://rinkeby.infura.io/INFURA_KEY", 
})
const web3 = new Web3(engine);`

Using contractInstance.eventName({<filters..>}).watch(callback) or anything similar shows the following error: 405 POST ERROR rinkeby.infura.io I have seen their github issues (https://github.com/INFURA/infura/issues/13, https://github.com/INFURA/infura/issues/10), but nothing seemed to be useful. No matter whatever I do, I can't seem to get web3 1.0 (tried setting providers as wss://rinkeby.infura.io/ws or rinkeby.infura.io/INFURA_KEY.

Its been over 2 hours and I have tried several different approaches. Please post any that works with either web3 0.19 or uport dApp!

EDIT: MINIMUM CODE:- SOLIDITY:

public uint id;
event TaskCreated(uint _id);
function addTask(uint _id) {
    id++; emit Taskcreated(_id); }

JS:

contractABI = <abi>
contractInstance = contractABI.at(<contract_address>);
var taskCreatedEvent = contractInstance.TaskCreated( {fromBlock:0, toBlock: 'latest' })
await taskCreatedEvent.watch((err,res) => {
            if (!err) {
                console.log(res);
                let id = res.args.id.toNumber();
                console.log(id)
            }
        })
  • Can you share a minimal, complete, and verifiable example of the code you are trying to get working? – Shawn Tabrizi Jul 22 '18 at 20:15
  • just added. Hope its enough to understand. – Rahul Kothari Jul 22 '18 at 20:21
  • Infura doesn't support filtering events, it does support subscription using websockets (and that requires web3 v1.0). If you are on web3 v0.20 you can use Web3 Provider Engine to filter events. – Ismael Jul 23 '18 at 2:58
  • Using the web3 Provider Engine gives an error. So can't use that – Rahul Kothari Jul 23 '18 at 9:53

Your Answer

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

Browse other questions tagged or ask your own question.