Hot answers tagged

7

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')...


5

From the docs: Given an event name and series of event parameters, we split them into two sub-series: those which are indexed and those which are not. Those which are indexed, which may number up to 3, are used alongside the Keccak hash of the event signature to form the topics of the log entry. Those which are not indexed form the byte array of the event....


5

In addition to the answer above, indexed parameters are slightly more expensive than unindexed parameters. The general formula for event gas cost is: 375 + 375 * numberOfIndexedParameters + numberOfUnindexedBits So in your example, the cost would be: event NewEvent(address addr) // 375 + 375 * 0 + 160 = 535 event NewEvent(address indexed addr) // ...


5

You have to do it without relying on anything that triggers at that moment. You use the block.number to decide if bets are allowed. function isOpen() { return(block.number <= deadline); } function bet( ... { require(isOpen()); ... } You determine a winner retroactively. function didIWin( ... { if(!isOpen()) return false; return winner() ==...


5

This is a bug in web3js, discussed here. And the following change fixes it (source): patch-package --- a/node_modules/web3-eth-abi/src/index.js +++ b/node_modules/web3-eth-abi/src/index.js @@ -280,7 +280,7 @@ ABICoder.prototype.decodeLog = function (inputs, data, topics) { var nonIndexedData = data; - var notIndexedParams = (nonIndexedData) ? this....


5

Currently it's a de-facto invariant that logs last forever. If the protocol is changed to get them pruned from the network this invariant will be broken and implementations relying on it too. Disclaimer: the rest of the answer is speculation. We should not underestimate the rigidity of a system with load on it. So I do not think that core devs are simply ...


3

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 }], '...


3

You're passing a hexadecimal string where bytes are expected. The code works with a few small changes: from eth_utils import decode_hex ... for log in logs: encoded_topics = [decode_hex(topic) for topic in log['topics'][1:]] indexed_values = [eth_abi.decode_single(t, v) for t, v in zip(indexed_types, encoded_topics)] #error occurs here ...


3

If two events are logged in one transaction, transactionIndex is going to be the same. In my opinion, using transactionHash and logIndex should enable you to identify unique event logs.


3

If the contract is verified in Etherscan, the following script fetches the ABI and saves it to a JSON file. Use it like $ python fetch_abi.py <contract address> -o <target JSON file> fetch_abi.py #!/usr/bin/python import argparse import requests import json # Exports contract ABI in JSON ABI_ENDPOINT = 'https://api.etherscan.io/api?module=...


3

If you want to deal with raw data I'd suggest to use a library like ethereumjs-abi. The rules used to encode/decode are in the solidity abi. In your case your data split into chunks of 20 bytes/40 hex look like 0000000000000000000000000000000000000000000000000000000000000040 000000000000000000000000000000000000000000000000000000000000001d ...


3

Problem We are considering how to query the Ethereum blockchain using the Web3 JS API to collect events, summarizing this data to find the most recent recipient of each ERC-721 token. Running your own infrastructure (Geth / Parity) is outside the scope of this question. Answer This answer uses Node.js. First, create this package.json: { "dependencies":...


3

While Aquila's answer can work as a workaround, the way truffleAssert.eventEmitted() works is by applying a filter function on the event's arguments. The drawback of this is that you can't "assert" each argument individually, but this will allow you to run both assertions in this fashion. I saw from your other question that you're using Truffle v5 with ...


3

I would suggest using my truffle-assertions library to assert whether events have been emitted. Using that, it doesn't matter what index an event has been emitted, just that it has been emitted. That means your assertions will be a bit less strict than they are currently, but it will be more readable and you won't experience the issues you faced with ...


3

throw rolls back the whole transaction, so it not only prevents event2 from being emitted, but also rolls back emission of event1. The final effect will be as if no events were logged at all, so you will see neither event1 nor event2 in transaction.


2

From the docs: Up to three parameters can receive the attribute indexed which will cause the respective arguments to be searched for: It is possible to filter for specific values of indexed arguments in the user interface.


2

Yes, it's possible. But web3.eth.subscribe works only with WebsocketProvider (or local IpcProvider). You need to do like this: const Web3 = require('web3'); let web3Provider = new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"); var web3Obj = new Web3(web3Provider); var subscription = web3Obj.eth.subscribe('logs', { address: '0x123456..', ...


2

I think it should be: myContract.events.LogJob.createFilter(fromBlock='latest', argument_filters={'arg1':10}) You can see the actual function signature here: https://web3py.readthedocs.io/en/latest/contracts.html?highlight=createfilter Please file an issue regarding web3.py documentation page as it does not reflect the current codebase.


2

@Maxpeinas, that's correct, you have to use websocket provider in order to subscribe to events in web3.js 1.0 via myContract.events.MyEvent() So, if you are using local TestRPC go with const web3 = new Web3('ws://127.0.0.1:8545'); If you are using remote endpoint - change it to ws, for example - Infura already have working websocket endpoints for the main ...


2

You can do this as following, var event = contract.myEvent(); event.watch((err, res) => { console.log(res); // event response // Do something on event; event.stopWatching() // Stop watching for the event once you've done what you wanted to do. }); It would btw be pretty nice if you could also post your node.js code. EDIT: Whats ...


2

I have found the answer myself after downloading Nethereum source code and trying to debug myself. The latest version requires us to put the [Event()] attribute for Event DTO


2

There's no meaning as far as Solidity is concerned. Some programmers choose to use a leading underscore for all function parameters, just as a convention to indicate that they're function parameters. They're also often used so as to avoid collisions, e.g.: uint256 totalSupply; constructor(uint256 _totalSupply) public { totalSupply = _totalSupply; } ...


2

I just tested it, and the events do get emitted. See: pragma solidity ^0.4.17; contract Test { address owner; constructor() public { owner = msg.sender; } event dying(bool dead); function kill() public { emit dying(true); selfdestruct(owner); } }


2

You should check these: Is searching data stored in event logs prohibitively slow? More specifically, what is the time complexity of eth_getLogs? In worst case, where every block contains log matching your query it is 0(n). But it's rarely a case. Bloom filters utilize probability of false positives, so the more sophisticated your filter ...


2

The web3.js 1.0 documentation states that the return value of creating an event is an EventEmitter. To close the event, you have to remove all of the EventEmitter's listeners using the bound event's names: // set up emitter: let emitter = contract.events.Deposit({}, function (err, event) { if (err) { console.error; } else { console....


2

If the two contracts don't inherit from each other and are deployed as separate contracts at separate addresses, it should not be a problem.


2

How safe is this? Can I 100% assume that if the event is fired then the bet was placed and I can safely add it to the database? The event is fired very fast on rinkeby and I'm worried a little bit. The event is fired when your node receives a block containing the transaction and the event. A possible caution item is that since your implementation ...


2

It comes down to how you are using the data and what is the most efficient method for you. It is true that you can get the msg.sender from the block (or transaction) or an event. If you are creating a front end and are populating the page with data from the event, it would likely be best to include it in the event for clean and concise front end code. If ...


2

First declaration of truffleAssert.eventEmitted handles all events, that is why you have the issue. It means you need to assert all events in single truffleAssert.eventEmitted or you can use workaround like: it("should check that the correct events are returned", async () => { let result = await contractInst.messages({from: user1}); ...


2

For the following event: event MyEvent(address indexed _arg1, bytes32 indexed _arg2, uint8 _arg3); You can extract the event arguments from the log like this // Event definition public static final Event MY_EVENT = new Event("MyEvent", Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Bytes32>(...


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