Hot answers tagged

39

One could consider topics as different index names. EVM uses low level primitives called logs to map them to high level Solidity construct called Event. Logs may contain different topics that are indexed arguments. Consider Event: emit PersonCreated(uint indexed age, uint indexed height); And you fire it in MyContract: function foobar() { ...


36

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify: var SolidityCoder = require("web3/lib/solidity/coder.js"); var log = receipt.logs[0]; var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", "")); In this case, we're decoding log data that ...


35

Logs are part of the transaction receipts. They are generated by the clients when executing transactions and stored alongside the blockchain to allow retrieving them. Logs are not part of the blockchain itself per se, since they are not required for consensus (they are just historical data), however they are verified by the blockchain as the transaction ...


32

Events in the ethereum system must be easily searched for, so that applications can filter and display events, including historical ones, without undue overhead. At the same time, storage space is expensive, so we don't want to store a lot of duplicate data - such as the list of transactions, and the logs they generate. The logs bloom filter exists to ...


29

Take a look at web3.eth.filter and watch. Something like this: const filter = web3.eth.filter({ fromBlock: 0, toBlock: 'latest', address: contractAddress, topics: [web3.sha3('newtest(string,uint256,string,string,uint256)')] }) filter.watch((error, result) => { // }) Note the part that "In Solidity: The first topic is the hash of the ...


26

Firstly, events are not accessible to contracts. The simple answer is Yes, events are permanently stored. The nuanced answer is Yes, events are as permanent as the blockchain. It helps to realize that events are the result of LOG opcodes being executed in the EVM. For an analogy, "internal transactions" are derived by executing transaction data through ...


23

I will try to anwser your question. I worked on bloom filters in cpp-ethereum and Parity. will retrieving event logs become prohibitively slow as the blockchain becomes larger? Not necessarily. Everything depends on the implementation, logs density (average number of logs / block) and number of cache levels. More specifically, what is the time ...


22

More recent versions of Parity allow native log file creation: parity --log-file /path/to/parity.log And set the log level to error, warn, info, debug or trace, with: parity -lsync,tpc=trace Where the following modules can be traced: account_bloom, basicauthority, chain, client, dapps, discovery, diskmap, enact, engine, estimate_gas, ethash, executive, ...


19

To get event logs of the past, you can instantiate the event with a block range, and use the myEvent.get function to retrieve events. In your example, we could do something minimal like this: let transferEvent = product.Transferred({}, {fromBlock: 0, toBlock: 'latest'}) transferEvent.get((error, logs) => { // we have the logs, now print them logs....


17

A contract cannot listen to events of another contract. From Solidity docs: Log and event data is not accessible from within contracts (not even from the contract that created a log). web3.js is a wrapper around JSON-RPC, so another way of accessing event data is via "filters" in JSON-RPC such as eth_newFilter. Note the dichotomy that a contract can'...


15

To help with @Peter's answer, it helps to realize what are events and logs. Events, logs, and event logs are usually Ethereum terms that are interchangeable (in some contexts a particular term is favored, for example events in Solidity and web3.js, and logs as in the EVM and Yellow Paper). Events/logs are the result of LOG opcodes being executed in the EVM....


15

Most of the answers for what's possible are in the Yellow Paper. From Equation 20, page 5: A log entry, O, is a tuple of a logger’s address, Oa , a series of 32-bytes log topics, Ot, and some number of bytes of data, Od There is no size limit to the data: you will be limited by how much Ether you have. (And of course the block gas limit.) If using ...


15

Your ideas for the first few fields are correct. The remainder are as follows: 0 Mgas/s - million gas processed/s 13399+ - unverified queue size 0 - verified queue size #2360201 - last imported block number 0/8/25 peers - number of active peers / number of known peers / configured maximum number of peers (this can be configured up to 50) 9 MiB db - ...


14

You are most likely looking for Events. Not only do they help with debugging, but they are useful in normal production code. Events are declared like functions, like so: event voteCast(address voter, uint votes, bool inFavor); Then somewhere (for example, in a vote counting function): function vote(bool inFavor) { var votes = shares[msg.sender]; /...


11

Use .get instead of .watch with web3.eth.filter: contractAddress = "0x00.." web3.eth.filter({ address: contractAddress, from: 1, to: 'latest' }).get(function (err, result) { // callback code here })


11

Tim: Thanks so much for the pointer. You forced me to finally understand some of the internals of web3.js. I found a cleaner way to do this that covers all the corner cases of the actually fairly complicated log message format (e.g. indexing). I just used SolidityEvent from web3 to do the already-tested work for me. Below is the code. I have this code ...


9

Print doesn't exist in Solidity. Use the logX statement as indicated in the manual instead.


8

The consensus blockchain doesn't contain any easily queryable information to figure out the creation time of a contract based solely on its address. If you have the hash of the transaction that created the contract, retrieving that would give you back the block number too. If you need only to occasionally figure out the creation block of a/some contracts, ...


8

Yes, a Merkle proof of a transaction receipt can be used to verify the existence of logs. An Ethereum block header has the Merkle root of the (transaction) receipts trie. A transaction receipt has all the logs. By hashing the transaction receipt, and the hashes comprising the Merkle proof, the resulting hash can be compared against the Merkle root in the ...


8

Turns out transaction receipt logs only include events emitted in the context of the direct contract function being called. If the called function makes another call to a separate external contract that emits an event, those won't be included even if there are emitted. To make use of those emitted events from other contracts: const sha3 = require('js-sha3')...


7

go-ethereum abi package in Oct 2017 got the update to unpack event output. Initially it was only able to unpack method output. All functionality is delivered through the abi.ABI object. To use it you need to have Event ABI (JSON string). Then use func (abi *ABI) UnmarshalJSON to construct the ABI object. From there you can use the Unpack method using Data ...


6

[I had to look at the code for this, so you might have to dig a bit more if the below isn't quite complete. (I think I've followed it correctly.) This is the Geth implementation.] The bloom filters are created in bloom9.go, by passing the receipt logs to CreateBloom(). func CreateBloom(receipts Receipts) Bloom { bin := new(big.Int) for _, receipt :=...


5

The test contract is not emitting an Event, that's why there's no logs. Return values are not automatically included as a log. Try: contract test { event R(uint x); function multiply(uint a) returns(uint d) { R(a * 7); return a * 7; } } In case that doesn't work, you might need to bump up the gas (you ...


5

No, they are not the same thing. The Bloom filter in the transaction (R_b) contains only the logs from this transaction while the Bloom filter in the block header (H_b) contains the logs from all transactions in this block. So yes, the information is stored twice, but with the benefit of being able to check quickly if a certain log is present in a block ...


5

Send Stderr And Stdout To A Log File If you want to overwrite the log file each time you start your command: parity [options] > /tmp/parity.log 2>&1 If you want to append to your log file each time you start your command: parity [options] >> /tmp/parity.log 2>&1 Send Stderr And Stdout To Separate Log Files While Viewing Output ...


5

The size limit of one event is a function of the block's gas limit, which as of now tends to be around 3,145,192 (i.e., the first seven digits of pi). According to Jonathan Patrick, logging costs 76 gas per byte. So I'd assume you could get in around 41kb per log event.


5

In a transaction receipt the fied topics correspond to your event arguments which are indexed in your smart contract. For all events you will find as first argument the hash of the event name, and then the data which are indexed in hexabytes. So in your case, in topics you will find 'topics':[hash_event_name,// w3.sha3(text='myEvent(uint256)').hex() where ...


5

Define a change event like event MyMapChange(address _addr, string _newName); and then, on each change, emit one like this: emit MyMapChange(myAddr, myNewName); Events get stored on the blockchain and can be queried, i.e. you can request request history, and also you can subscribe to new events, and even filter them by field values. To enable field ...


4

In web3 1.0 you can use getPastEvents as follows var contractInstance = new web3.eth.Contract(contractAbi, contractAddress); contractInstance.getPastEvents('EventName', { filter: {id: id}, fromBlock: 0, toBlock: 'latest' }, (error, events) => { if (!error){ var obj=JSON.parse(JSON.stringify(events)); var ...


4

You can now use the web3.eth.abi.decodeLog function (web3 1.0). Example from the documentation: web3.eth.abi.decodeLog([{ type: 'string', name: 'myString' },{ type: 'uint256', name: 'myNumber', indexed: true },{ type: 'uint8', name: 'mySmallNumber', indexed: true }], '...


Only top voted, non community-wiki answers of a minimum length are eligible