Solidity

如何在巧克力蛋糕中獲得契約發出的事件?

  • January 27, 2022

假設我有一個發出多個事件的契約,我如何獲取在 brownie 中發出的所有事件的列表並按事件類型對它們進行排序?

contract SimpleContract {
 
 event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
 event Withdraw(address indexed _to, bytes32 indexed _id, uint _value);

 function deposit(bytes32 _id) external {
   emit Deposit(msg.sender, _id, msg.value);
 }

 function withdraw(bytes32 _id, uint value) external {
   emit Withdraw(msg.sender, _id, value);
 }
}

events呼叫函式(創建事務)時,您可以使用屬性檢查事務事件。

simple_contract = SimpleContract.deploy({"from": account})
tx = simple_contract.deposit(bytes_arg, {"from": account})
print(tx.events)
print(tx.events[0]["Deposit"])

引用自:https://ethereum.stackexchange.com/questions/119994