0

I'm not able to watch and log event sent by smart contract using the Ropsten test network. The same code works on local test network.

Contract Event code:

event CreateOptionEvent(address indexed _who, uint256 indexed _date, uint256 indexed _id);

function createOption( ...PARAMS HERE... ){

    [...]

    emit CreateOptionEvent(msg.sender, now, optionId);
}

Web app event code:

createEvent = myContractInstance.CreateOptionEvent({ fromBlock: 0, toBlock: 'latest' })
createEvent.watch((err, result) => {
    if (err) {
        console.log(err)
        return;
    }
    console.log(result.args._id)
})

After I correctly create an option (transaction success on metamask) nothing is logged.

What should I try to do?

-> % truffle version 
Truffle v4.1.11 (core: 4.1.11) 
Solidity v0.4.24 (solc-js)
1

You can subscribe to events as shown in Web3 documentation. Also you would need to create new instance with websocket provider for it (for example wss://ropsten.infura.io/ws) as MetaMask doesn't support websockets i believe.

  • Can you please link a tutorial or explain how to create a websocket provider. Anyway on custom RPC testnet i'm able to log event. Only on ropsten i can't do it. Thank you – Takeda925 Jun 23 '18 at 19:02
  • Everything is in Web3 documentation web3js.readthedocs.io/en/1.0/web3.html#setprovider . You can use Infura ws on both testnets and on main-net too. – Maxpeinas Jun 25 '18 at 2:39

Your Answer

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

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