Reading and Writing Data
While it is costly to store, read, and modify data, these storage operations are a necessary component of most smart contracts. Smart contracts can write data to two places:
Global state
The state variables in a given smart contract are stored in Ethereum’s global state trie; a smart contract can only store, read, and modify data in relation to that particular contract’s address (i.e., smart contracts cannot read or write to other smart contracts).
Logs
A smart contract can also write to Ethereum’s chain data through log events. While Vyper initially employed the __log__
syntax for declaring these events, an update has been made that brings its event declaration more in line with Solidity’s original syntax. For example, Vyper’s declaration of an event called MyLog
was originally MyLog: __log__({arg1: indexed(bytes[3])})
. The syntax has now become MyLog: event({arg1: indexed(bytes[3])})
. It is important to note that the execution of the log event in Vyper was, and still is, as follows: log.MyLog("123")
.
While smart contracts can write to Ethereum’s chain data (through log events), they are unable to read the on-chain log events they’ve created. Notwithstanding, one of the advantages of writing to Ethereum’s chain data via log events is that logs can be discovered and read, on the public chain, by light clients. For example, the logsBloom value in a mined block can indicate whether or not a log event is present. Once the existence of log events has been established, the log data can be obtained from a given transaction receipt.