Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. contract MyContract {
  4.  
  5. string message;
  6. event MyEvent(address contractAddress, string message);
  7.  
  8.  
  9. constructor() public {
  10. message = "I'm ready!";
  11. }
  12.  
  13. function setGreetings(string _message) public {
  14. message = _message;
  15. }
  16.  
  17. function getGreetings() public view returns (string) {
  18. return message;
  19. }
  20.  
  21. function triggetEvent() public {
  22. MyEvent(address(this), message);
  23. }
  24.  
  25. }
  26.  
  27. web3 = Web3j.build(new HttpService("http://localhost:9545/"));
  28. Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
  29. MyContract myContract = MyContract.load(CONTRACT_ADDRESS, web3, credentials, GAS_PRICE, GAS_LIMIT);
  30. EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, myContract.getContractAddress());
  31. String encodedEventSignature = EventEncoder.encode(MyContract.MYEVENT_EVENT);
  32. filter.addSingleTopic(encodedEventSignature);
  33. log.info("subscribing to event with filter");
  34. web3.ethLogObservable(filter).subscribe(eventString -> log.info("event string={}", eventString.toString()));
  35.  
  36. public static final Event MYEVENT_EVENT = new Event("MyEvent",
  37. Arrays.<TypeReference<?>>asList(),
  38. Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement