iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 8
1
影片教學

Smart Contract 實戰教學系列 第 8

Event & Log

送出 transaction 之後,我們應該怎麼追蹤 transaction 執行的結果呢?我們有沒有什麼樣的方式可以在 transactions 的茫茫大海中過濾出需要的資訊呢?
這時候就輪到 Event & Log 出場啦~

本日合約:

pragma solidity ^0.4.25;
contract Test {
    string information;
    uint balance;
    
    event LogCreate(string information, uint balance);
    event LogCreateIndex(string indexed information, uint indexed balance);
    
    constructor() public {
        information = "default";
        balance = 100;
        emit LogCreate(information, balance);
        emit LogCreateIndex(information, balance);
    }
}

執行過後看一下 logs 裡面的差異吧!

本日影片:
https://youtu.be/Rai_6k0jk3U

Smart Contract 實戰教學播放清單:
https://www.youtube.com/playlist?list=PLHmOMPRfmOxSJcrlwyandWYiuP9ZAMYoF


上一篇
Assert, Require, Revert
下一篇
Fallback function
系列文
Smart Contract 實戰教學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 則留言

0
alincode
iT邦新手 1 級 ‧ 2018-10-23 23:48:24

提醒:這篇忘記掛到,播放清單下了。

hydai iT邦新手 4 級 ‧ 2018-10-24 17:09:45 檢舉

已更新~謝謝提醒

0
cheriish2001
iT邦新手 5 級 ‧ 2019-05-22 18:12:55

不好意思 小弟想請教

如果想要查詢歷史的交易資訊

要如何搜尋呢?

(透過Topics or....)

hydai iT邦新手 4 級 ‧ 2019-05-28 15:50:20 檢舉

不知道你想要查的交易資訊包含哪些東西呢?
如果只是想知道一般 transaction 成功與否等,可以直接用 etherscan 看該 transaction 或者用 geth 直接去 getTransaction 來看到。
如果是想要撈到 event & log 的資訊的話,就需要使用 web3 的幫助,比如說像是這個 stackoverflow 的 answer 這樣操作:
https://ethereum.stackexchange.com/questions/2024/how-to-access-the-event-log-by-knowing-the-contract-address-web3

我要留言

立即登入留言