1

When I watch a contract for transaction events in web3.py or web3.js,

In web3.js

var contract = web3.eth.contract(abi);

var cInstance = contract.at(address);

var transferEvent = cInstance .Transfer({}, {fromBlock: 0, toBlock: 'latest'});    

transferEvent.watch((error, event) => {});

In web3.py

contract = w3.eth.contract(abi=contract_interface['abi'], address='0x....')

tfilter = contract.on('Transfer',{'fromBlock':0,'toBlock':'latest'})

def transfer_callback(tnx):
    print(tnx)

tfilter.watch(transfer_callback)

Is it guaranteed the callback will be fired according to the order of the transactions? even for past transactions. e.g. first transaction will be fired first, and second transaction will be fired second and so on.

Please note I'm filtering 0 block to latest. So above code should get all past transaction events too.

  • I'm not sure if I'm understanding this correctly but if you fire multiple transactions and wait for their events there is no guarantee which transaction gets processed first in a public network. Miners decide on the order of the transactions. But if you don't care about this ordering then I'd assume the first event to come from the node is from the first tx processed. – Lauri Peltonen Jul 15 at 17:08
0

Almost all of the filtering logic resides on the node, currently. So the exact answer depends if you're using geth or parity or something else. I've never seen anything but in-order events in my limited event experimentation in the different nodes.

Update for geth: In my experience, they always return in order. I wasn't able to find any documentation to confirm it, and didn't have a chance to find it in the go code. I wouldn't assume it always is this way. You could always just add an assertion that throws or warns if the block number decreases on any of the logs.

  • I'm running the node using geth --rpc – EastSwan Jan 13 '18 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.