In developing with smart contracts (not specifically OpenZeppelin Contracts or OpenZeppelin SDK) event
is used to access data form a smart contract logs. I plan on using polling with setInterval to access event data into my UI.
In practice I run into difficulty in the event parameter syntax, any help would be appreciated. Here is the pattern shown in the web3 docs:
//version 0.2.x:
var event = myContractInstance.myEvent({valueA: 23} [, additionalFilterObject])
// watch for changes
event.watch(function(error, result){
if (!error)
console.log(result);
});
// Or pass a callback to start watching immediately
var event = myContractInstance.myEvent([{valueA: 23}] [, additionalFilterObject] , function(error, result){
if (!error)
console.log(result);
});
I use truffle to access my contract methods etc… so here is my code whereby I omitte the first parameter since that is optional(?) (Note: NewData
is my contract event name)
myContract.deployed().then((instance) => instance.NewData.watch(function(error
, result) { if (!error)
console.log(result)
this.currentNumber = result;}))
web console error:
Unhandled promise rejection TypeError: missing argument 1 when calling function instance.NewData.watch