Hot answers tagged

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

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

You can easily achieve this using ProvenDB. Here is an example code written in Go to continuously prove your logs' existence and ownership on Blockchain: https://github.com/SouthbankSoftware/provenlogs. Hope it helps :P


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

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

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

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

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

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

If you're using Web3 v1 then you can use web3.eth.getTransactionReceipt(tx). It returns logs property as a part of a result. You can categorize events by looking at their topics property. Sample getTransactionReceipt result: { "transactionHash": "0x7e2e90d913246933b30049c568d9a9768eca5be6fed331656458c2a479f30908", "transactionIndex": 0, "...


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.


2

I always use myContract.func.call(). Actuall I have never heard that myContract.func(). After all this is the recommended way of doing it!! Furthermore, the performance is better (I think). Maybe that's your perception? Read the official web3 documentation. I read every page of it. Here is the link to the correct article. I don't use truffle and it works ...


2

I think this is what you are looking for: const Web3 = require('web3'); const web3 = new Web3('wss://ropsten.infura.io/ws/v3/<yourID>'); const abi = "placeYourABI"; const address = 'yourContractAddress'; const contract = new web3.eth.Contract(abi, address); contract.getPastEvents('allEvents', { fromBlock: 0, toBlock: 'latest' }).then(...


2

You need to verify and publish your smart contract code in order for Etherscan to pick up the event names.


1

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


1

Listen to contracts, not addresses. You listen to the ERC20 contracts for transfer events. On the client side, check your list to see if the transaction is of interest. Hope it helps.


1

According to this, the web3 provider URL should look something like: wss://ropsten.infura.io/ws/v3/YOUR-PROJECT-ID


1

A smart contract directly cannot perform action which have a scope outside of the EVM. If this wasn't the case, the contract will be prone to nondeterministic gas usage. A possible solution is to create a server to watch changes on the chain and perform the corresponding action on the database to keep it in sync. This might help you: How can an Ethereum ...


1

Your update function appears to only consume your event once: export const update = (callback) => { contract.LoggingString((error, result) => callback(error, result)); } Once the callback you pass into this function has run, execution is complete and so further events have no callbacks to fire. Instead, you want to use web3 to subscribe to a ...


1

Basically, each event contains up to 5 "topics", plus arbitrary binary payload. By convention, first topic is an address of a smart contract that logged the event. Second topic is a keccak256 hash of event's signature, i.e. string looking like OwnershipTransferred(address,address). Three other topics are for indexed parameters of the event, and binary ...


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