1

This question already has an answer here:

My event call is

event AmountChanged(address indexed purchaser,  uint256 value);

My function in solidity

function () external payable {   
    uint256  amountinwei = msg.value; 
    AmountChanged(msg.sender, msg.value);
}

When i am calling it through web3

contractinstance.AmountChanged({}, {fromBlock: 0, toBlock: 'latest'}).watch(function(err, result){
    console.log(result);
    console.log(err);
});

I am getting error ----

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/Volumes/Macintosh HD 2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/web3/lib/web3/errors.js:38:16)
    at XMLHttpRequest.request.onreadystatechange (/Volumes/Macintosh HD 2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Volumes/Macintosh HD 2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Volumes/Macintosh HD 2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/Volumes/Macintosh HD 2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/Volumes/Macintosh HD2 2/MorpheusApiGit/WebServices/Node-API-Morpho/node_modules/xhr2/lib/xhr2.js:469:24)
    at IncomingMessage.emit (events.js:164:20)
    at endReadableNT (_stream_readable.js:1054:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

using web3@0.19.1 web3.providers.HttpProvider("https://rinkeby.infura.io/")

Thanks in advanced

marked as duplicate by Ismael, Richard Horrocks, mirg, Achala Dissanayake, eth Apr 17 '18 at 4:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

We can use

npm install web3-provider-engine

to listen event from smart contract

Thanks.

0

As I recall, Infura doesn't support the HTTP-based API for watching events. You'll need to use a different provider or filter through log messages yourself like MetaMask does.

  • Can you please provide some sample code and different provider or filter. Also, when we go live does main net of infura support http-based API ??? – user23593 Feb 9 '18 at 9:05
  • Mainnet has the same restriction. Can you explain your scenario? Your users won't be using Mist or MetaMask? Is your app read-only? – smarx Feb 9 '18 at 9:37
  • We are creating a crowd sale contract, we have tested this properly using truffle, we now wish to check this on rinkeby. However when we go live on the client side when we use web3, we would like to connect to mainnet without downloading it, thats why we choose infura. Can you please guide us, how to test this on rinkeby and which provider to use when we go live..... Thanks for your support – user23593 Feb 9 '18 at 9:44
  • Users won't be able to buy tokens unless they have something like MetaMask (or they trust you with their private keys). – smarx Feb 9 '18 at 9:50
  • User would send ether to our contract and we would listen to event using web3. So, which web3 provider should we use on mainnet as event dont work with infura?? Also, how contract are deployed on main net – user23593 Feb 9 '18 at 9:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.