Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.24;
- contract MyContract {
- string message;
- event MyEvent(address contractAddress, string message);
- constructor() public {
- message = "I'm ready!";
- }
- function setGreetings(string _message) public {
- message = _message;
- }
- function getGreetings() public view returns (string) {
- return message;
- }
- function triggetEvent() public {
- MyEvent(address(this), message);
- }
- }
- web3 = Web3j.build(new HttpService("http://localhost:9545/"));
- Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
- MyContract myContract = MyContract.load(CONTRACT_ADDRESS, web3, credentials, GAS_PRICE, GAS_LIMIT);
- EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, myContract.getContractAddress());
- String encodedEventSignature = EventEncoder.encode(MyContract.MYEVENT_EVENT);
- filter.addSingleTopic(encodedEventSignature);
- log.info("subscribing to event with filter");
- web3.ethLogObservable(filter).subscribe(eventString -> log.info("event string={}", eventString.toString()));
- public static final Event MYEVENT_EVENT = new Event("MyEvent",
- Arrays.<TypeReference<?>>asList(),
- Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement