Hot answers tagged

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


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


5

This web3 version is a few years old you should probably use a new one. Make sure to update!


4

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


4

If I understand correctly your want to upload a file from the client machine to the web application using the standard HTML tag <input type="file"> and then hash the content of the file. Your code is actually hashing the full path of the file. If you want to read the content of a file, I recommend to use FileReader like this: HTML: <div> &...


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

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

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

@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 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

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

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

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

Note when applying this for structs, the pattern is to nest the structs in a similar way. So: keccak256("Deposit(address,bytes32,uint256,(bytes32, bytes32))") is the signature of the event: struct MoreData { bytes32 id1; bytes32 id2; } event Deposit( address indexed _from, bytes32 indexed _id, uint _value, ...


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

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

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>(...


2

Seeing as nobody else is answering, I could provide you with an answer of some sorts. First things first: your contract is not valid with the compiler version you are implying in the code (0.4.22) - keyword constructor did not exist back then and you had to use constructors in a different way. But, I see you are in reality using 0.4.24 so all's fine. If ...


2

No, smart contracts can't read the content of the event logs. As it says in the docs: The Log and its event data is not accessible from within contracts (not even from the contract that created them).


2

I would add a word of caution to what @ivicaa said because there is a subtlety to be aware of when coding a software client (could be a server) that listens to logs. Software clients need to be aware of transaction confirmations and finality rules because log emissions are part of confirmed transactions. The same uncertainty applies. Log entries may be ...


2

Alright, let's start from scratch. Let's say you have a very simple contract which increments and decrements a counter deployed to the address CONTRACT_X pragma solidity ^0.4.20; contract Counter { int counter; // Global state event CounterIncremented(address indexed _by, int _newValue); event CounterDecremented(address indexed _by, int ...


2

This is a bit convoluted since Web3 does not directly expose events emitted by a transaction, but it can be queried by tracing the transaction. Trace transaction : https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction It will return a block of info for each instruction of transaction. (PUSH1 in this example) { depth: ...


2

You may listen to many addresses via one subscription: https://web3js.readthedocs.io/en/1.0/web3-eth-subscribe.html#subscribe-logs Also you may omit address parameter and listen for all Transfer events from all tokens.


2

The problem is that there are different type of Transfer events which share the same signature. The ERC20 transfer event is defined as: Transfer(address indexed _from, address indexed _to, uint256 _value) And the ERC721 (the standard for non-fungible/unique assets on the Ethereum blockchain) defines the transfer event as: Transfer(address indexed _from, ...


2

The reason is because what is being emitted is an indexed dynamic variable, not static. Solidity stores a keccak256-hash when indexing a dynamic variable, so the string you are getting, 0xb6e... is the keccack256-hash of the string "Hello, world!". More information can be seen here in the Solidity docs. There are two ways you can handle this: 1) Remove ...


2

You should not specify the types of parameters when you pass them in a function-call: users[userID] = kullanicilar(string name, string surname, age); Change it to: users[userID] = kullanicilar(name, surname, age);


2

The order of arguments is always the same, though their names may vary. Also, you are supplying your own ABI file, so you most likely use argument names given in that ABI file. The EVM/Solidity wire protocol hashes only argument types, not their names, so the actual name is irrelevant in the raw blockchain data. A lot of tokens were deployed before ERC-20 ...


2

Solidity variable values can only be set from the contract. So you will definitely need some sort of setter functionality for the variable to be set to different values. Furthermore there is no functionality to "watch" a variable's value or something similar. You simply have to do the monitoring yourself. So when you implement functionality to set the ...


2

Geth is an ethereum client but it is not a high performance RPC server. To resolve some calls like getPastEvents it has to traverse a lots of history. It was never designed to respond to thousands of queries per second. If you want to achieve such performance it is better to store the events you are interested in a suitable database.


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