Ganache is a great, almost one-click development Ethereum you can use on desktop. One thing many folks complain about is not being able to see Events and Contracts in Ganache when they are expected.
Actually, if a Truffle project is configured, the Contracts and Events will show up in the Ganache dashboard.
These are very handy to get Contract and Events, a lot easier than using truffle console and web3.js.
contract MyContract {
event MyEvent(address indexed from, string message);
constructor() public {
}
function foo() public {
emit MyEvent(msg.sender, 'hello foo');
}
}
truffle-config.js should have interface and sol files directories, such as:
You would often want to monitor what’s going on with the contract on the Ethereum network, especially your own contract. For this, you need to do (1) emit some events on the network (2) subscribe to the event based on address and /or topics.
Emit event in Solidity
pragma solidity >=0.7.0 <0.8.0;
contract LogEventExample {
event MyEvent(address indexed a, uint256 v); // indexed will be in topic
function triggerEvent() public payable {
emit MyEvent(msg.sender, 1);
}
}
Make sure –ws is enabled if using geth. Websocket allows monitoring of the event after subscribe.
When you play with web3.js, if you want to connect to Ethereum mainnet quickly without using real account, you can use the Infura as the bridge to get into the ETH2. Infura provides a nice layer to manage/monitor the access to Ethereum.
A few main steps:
Go to Infura.io to register for free (with limited daily requests).
Create a new project called Dapp1, or whatever you like.
Get a https or websocket URL which comes with API token, such as:
You must be logged in to post a comment.