We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

63

Q What does the "indexed" keyword do in the below line of code? I'm guessing it just tells the event object that the following input should be logged? The indexed parameters for logged events will allow you to search for these events using the indexed parameters as filters. Q Can we use it other places ie outside of events? The indexed keyword is only ...


12

Filters work a little bit different. Filters require LOGs to be emitted from an EVM execution (i.e. a contract). Solidity makes this easy for you by allowing you to fire events (compiled events generate LOGs). Let's take the following contract: contract T { event res(uint indexed out) function echo(uint in) { res(i); } } When the ...


9

The indexed keyword helps you to filter the logs to find the wanted data. thus you can search for specific items instead getting all the logs. in general : event <Identifier>(<parameters>) Where at most 3 parameters can receive the property indexed. If called as a function, issues a log opcode containing the non-indexed arguments as data, ...


9

eth_getLogs returns an array of filter logs. You pass in the parameters - e.g. fromBlock, toBlock, etc. - you want to discriminate against. These are the same parameter used by eth_newFilter. eth_newFilter takes the same parameters, but returns a filterId instead of an array of logs. This ID can then be passed to eth_getFilterLogs, which returns the array ...


9

Thank you @BokkyPooBah for the general idea, but the final code is a bit different from what you wrote. The prototype to subscribe an event in solidity is (I'm using web3): SolidityEvent.prototype.execute = function (indexed, options, callback) So, the first parameter is indexed which I pass an empty object. Options parameter should have the block ...


8

Latest means the latest block that is already inside your own chain. All transactions contained within can be considered successfully executed. Security wise of course there can be reorgs, but in general they are executed transactions. Pending on the other hand is the collection of transactions that can be executed by the network (that your own node knows ...


8

If you are not familiar with node.js but with PHP and the ethereum architecture, I recommend you to have a look on the RPC API: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter In particular at eth_newFilter and eth_getFilterChanges which you can simply call via rest API e.g. # This will install a new filter with your desired address curl -X ...


7

EDIT 03/06/2016 Corrected this example, adding {} as the first parameter to theDAO.Voted(...) as suggested by @Pablo Yabo. Added code sample to filter for Voted events from selected address(es) and/or proposalID Here's the code and sample results to retrieve the Voted event from The DAO via geth console: > var theDAOABI = [{"constant":true,"inputs":[{"...


6

When I started working on Ethereum even I was having issues similar to this and I learned the hard way. I will share what I learned from my mistakes and hope you don't end up doing the same. Answer to your question: Is there anything being done wrong above? I expected to get some values in the result array and I don't know why it is empty. I think you ...


5

Here I am listing an example how I have applied event filter In this example I have used the candidate name as a filter parameter. Secondly it is looking from block 0 to latest. Hope this helps. Event Declaration - Solidity Contract event RegisterCandidate(uint256 indexed eventTimeStamp, address indexed _from, bytes32 indexed _candidateName); Code in ...


5

You can find an open issue in the Infura Git We're working on finding a solution to this which can provide the functionality createFilter/getLogs was providing in a way which is scalable and secure. This feature is "Stateful Transaction Support" and is tracked in this issue #10


5

Infura doesn't support filters. Per https://api.infura.io/v1/jsonrpc/ropsten/methods (from the documentation, these are the supported methods: { "get": [ "web3_clientVersion", "net_version", "net_listening", "net_peerCount", "eth_protocolVersion", "eth_syncing", "eth_mining", "eth_hashrate", "eth_gasPrice", "...


4

TestRPC doesn't support past events unfortunately. You could try using a private Geth chain as detailed here.


4

Unfortunately, there is no filter provided to parse the confirmed transactions without going through a block first i.e., you can trigger a filter (and execute call_async_method()) whenever there is a latest block: eth.getBlock("latest"), but there is no such function for a transaction. That said, if you're operating on a private blockchain (you trust all ...


4

You should be able to specify the period (in block no) to watch. According the documentation here fromBlock: Number|String - The number of the earliest block (latest may be given to mean the most recent and pending currently mining, block). By default latest. toBlock: Number|String - The number of the latest block (latest may be given to mean ...


4

Answering own question. const Web3 = require('web3') let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")) let account = '0x05430f5201585c2601bb75d9658007202864c993' let filter = web3.eth.filter('latest') filter.watch(function(error, result) { if (!error) { let confirmedBlock = web3.eth.getBlock(web3.eth.blockNumber - 11) ...


4

So this can be done by watching for contract events, optionally from a specified sender, and then filtering the result by the transaction hash. Here's an example using web3.js: const Web3 = require('web3'); const web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider('http://127.0.0.1:8545')); const multiSigWalletFactoryAddress = '0xF935......


4

From the documentation watch will only looks for state changes, ie only new blocks added from the last time geth was running will be reported. We found it somewhat unreliable, if there was a chain reorganization some events were not fired although the transaction was incorporated in the blockchain, or they were fired but the transaction was removed in the ...


3

In your specific case that would be: var myEvent = contract.myEvent({id: 1}); myEvent.watch((error, result) => { var data = result["args"]["data"]; var id = result["args"]["id"]; // always 1 // Do Something }); Which would watch only events with id = 1.


3

Just checked. In current Geth (v1.5.7), eth_getFilterChanges returns {"jsonrpc":"2.0","id":168,"result":[]} when there is no changes. {"jsonrpc":"2.0","id":168,"error":{"code":-32000,"message":"filter not found"}} when filter id not exists e.g. after timeout And according to source (https://github.com/ethereum/go-ethereum/blob/...


3

You can use the following method in web3py to get events: myfilter = mycontract.eventFilter('EventName', {'fromBlock': 0,'toBlock': 'latest'}); eventlist = myfilter.get_all_entries() eventlist will be a list of dictionaries containing the parameters of each event that had happened. Hope this helps.


2

From a question about pending: Pending is the collection of transactions that can be executed by the network (that your own node knows about), but have not yet been done so. If your node sends a transaction, you should see its transaction hash being logged. Send a second transaction, and you should see its hash. This documentation may be clearer as:...


2

Ok, these are blockhashes. From web3 api: When using the "latest" parameter, it returns the block hash of the last incoming block.


2

Have a look at this related question. You can query for the transaction based on all transaction fields. If you are planning on querying the block chain from within a contract bear in mind that you can access only specific fields of the block that the contract was mined to.


2

Yes,You could use the stopWatching() function to each of the filters when you want them to stop functioning. var filter = <your filter code>; //now you want to stop them being functional filter.stopWatching(); Will do what you want. Running eth.filter() command on the JavaScript console gives a list of all the filters along with the unique ...


2

[Disclaimer: My answer is based on reading the code.] From the filters code - filter.go and, more importantly, filter_system.go - there doesn't appear to be an imposed limit. The filterId variable is an int and is sequentially incremented for each new filter, but no overall count is maintained in the code, nor does there appear to be a buffer.


2

The filter ID is an integer, and is incremented for each newly created filter, regardless of the parameters it's created with. See also the following previous thread: What's the maximum number of filters geth can hold and what happens when this maximum is met?


2

How to get all the events with the passed id. As indicated by @cees-van-wijk, this fetches every new event: var myEvent = contract.myEvent({id: 1}); myEvent.watch((error, result) => { var data = result["args"]["data"]; var id = result["args"]["id"]; // always 1 // Do Something }); this fetches all previous events myEvent.get((error, ...


2

Partial answer: it may be that you can't get a block number with var block = web3.eth.getBlock(result, true); alert(block.number); because the block is "pending", in which case its number will be null (see web3.eth.getBlock return value description).


2

Since you specified {fromBlock: 0, toBlock: 'latest'}, your code will catch all Rate events logged by the contract lms since its creation, to the latest block mined when the watch function is called. It will only retrieve the events logged by that specific contract, not any other.


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