I wrote a very simple smart contract which emits an event everytime I call one of its functions:
pragma solidity ^0.8.0;
contract MyContract {
event Score(
uint date,
string player,
string team
);
function goalScored(string memory _player, string memory _team) external {
emit Score(block.timestamp, _player, _team);
}
}
Then I deploy the contract using truffle migrate
. Finally I interact with the contract within the truffle console
.
To do so I therefore load the contract by using the following lines of code:
MyContract.deployed().then(function(i) { contract=i;})
contract.goalScored('messi','inter')
Basically everytime Messi scores against a team a I launch the function to emit an Score event.
Here is my question: how can I visualize the list of all events within the truffle console?
What I tried: I ran the goalScored() function 4 times with different inputs and then I tried to used the following command:
contract.allEvents()
But all I got was this:
EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
}
truffle(development)> Uncaught [Error: The current provider doesn't support subscriptions: HttpProvider] {
domainEmitter: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
},
domainThrown: false
}
Would you be able to suggest a smart and elegant way to achieve my goal?
Best Answer
from truffle develop you could try something like
furthermore, if you need ALL events, you could use
full truffle develop input:
example output: