【anonymous】
anonymous
: 不會儲存任何的事件的signature
在topics
內
不同於一般的 events
,匿名事件不會包含任何 indexed
signature
的 keccak
加密結果。因為他們不可以被簡單地搜尋或被特別地解密,除非我們擁有合約 ABI。
要使一個合約為匿名(anonymous
)可以在每個變數後面加上 anonymous
:
contract TestContract {
event Start(uint start, uint middle, uint end) anonymous;
event End(uint start, uint middle, uint end) anonymous;
在 Solidity 中匿名 event
會耗費較少的成本,然而我們不能夠使用 name 找到他們,只能使用特定的 contract address:
pragma solidity >=0.4.21 <0.7.0;
contract ClientReceipt {
event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
);
function deposit(bytes32 _id) public payable {
// Events are emitted using `emit`, followed by
// the name of the event and the arguments
// (if any) in parentheses. Any such invocation
// (even deeply nested) can be detected from
// the JavaScript API by filtering for `Deposit`.
emit Deposit(msg.sender, _id, msg.value);
}
}
Last updated
Was this helpful?