All Products
Search
Document Center

Blockchain as a Service:Events and Logs

Last Updated:Jan 03, 2020

Events are a log infrastructure provided by Ethereum Virtual Machine (EVM). They record operations and are saved as logs. They can also be used to notify the UI, provide the results of function calls, and other interactions. Logs and events bridge the platform and end users.

Contract log example

You can use logs and events to obtain the execution status of the contract code. An example contract is provided as follows:

  1. pragma solidity ^0.4.0;
  2. contract ClientReceipt {
  3. event Deposit(
  4. identity indexed _from,
  5. uint _id,
  6. uint _value
  7. );
  8. function deposit(uint _id) {
  9. Deposit(msg.sender, _id, msg.value);
  10. }
  11. }

After the contract is deployed, you can call the deposit(uint256) method to obtain events in a log. You can use the event keyword to define an event. The parameter list of the event includes the names and types of parameters you want provide in a log. Outputs of the contract log are as follows:

  1. from: 1122334455667788991011121314151347181920929293949596979812345678
  2. to: 10237462546362184738205736165f7391947195472655869214456471048395
  3. log_data:00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000032
  4. topics: [90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15
  5. 1122334455667788991011121314151347181920929293949596979812345678]

The outputs include the following properties: from, to, log_data, and topics. For information about the detailed log structure, see Contract log structure.

Contract log structure

The log outputs generated by calling the deposit(uint256) method show the contract log structure supported by the platform.

Property Type Length (bit) Description
from identity 256 The ID of the contract caller.
to identity 256 The ID of the called contract.
topics string Not defined The contract log topics, including user-defined topics. To define a topic, you need to add the indexed keyword in the input parameter declaration of an event. For more information, see Contract log example.
log_data bytes Not defined The contract log data. You can obtain the outputs of the example contract log after calling a contract.

For more information about logs and events, see Solidity official documentation.