{"id":2761,"date":"2020-06-30T23:49:02","date_gmt":"2020-06-30T11:49:02","guid":{"rendered":"http:\/\/www.talkcrypto.org\/blog\/?p=2761"},"modified":"2020-07-14T13:03:32","modified_gmt":"2020-07-14T01:03:32","slug":"solidity-events","status":"publish","type":"post","link":"https:\/\/www.talkcrypto.org\/blog\/2020\/06\/30\/solidity-events\/","title":{"rendered":"Solidity events"},"content":{"rendered":"\n<p>In Solidity, firing or emitting events is a handy tool that you can employ not only to log messages for simple debugging but more importantly Dapps or anything connected to the Ethereum JSON-RPC API can listen to these events and act accordingly. Events can also be indexed so that the event history is searchable later as well. <\/p>\n\n\n\n<p>Here is a very simple example of creating an event.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pragma solidity ^0.6.0;<br> contract EmitEvent {<br>     event log();<br>     function triggerLog() public {<br>         emit log();<br>     }<br> }<\/pre>\n\n\n\n<p>You first have to declare the event and then give it a name along with the parameters you want to pass around. The above example does not have any parameters. The example below has one parameter.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pragma solidity ^0.6.0;<br> contract EmitEvent {<br>     event log(string _logmessage);<br>     function triggerLog() public {<br>         emit log(\"hi\");<br>     }<br> }<\/pre>\n\n\n\n<p>The event gets displayed in the logs of the transactions in remix. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"479\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/logging-events-1024x479.png\" alt=\"\" class=\"wp-image-2762\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/logging-events-1024x479.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/logging-events-300x140.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/logging-events-768x359.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption><br><\/figcaption><\/figure>\n\n\n\n<p>Watch the video below for a walkthrough.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Simple intro into Solidity events with examples\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/y3imdjTtP-I?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Solidity, firing or emitting events is a handy tool<\/p>\n","protected":false},"author":1,"featured_media":2764,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2761","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ethereum"],"featured_image_urls":{"full":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"thumbnail":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events-150x100.jpg",150,100,true],"medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"medium_large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"1536x1536":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"2048x2048":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"chromenews-featured":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"chromenews-large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false],"chromenews-medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2020\/06\/events.jpg",194,100,false]},"author_info":{"info":["seandotau"]},"category_info":"<a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/ethereum\/\" rel=\"category tag\">Ethereum<\/a>","tag_info":"Ethereum","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/comments?post=2761"}],"version-history":[{"count":4,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2761\/revisions"}],"predecessor-version":[{"id":2788,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2761\/revisions\/2788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media\/2764"}],"wp:attachment":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media?parent=2761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/categories?post=2761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/tags?post=2761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}