0

I am trying to listen for recently mined events from a live smartcontract(EtherDelta).

      //https://github.com/praneethmendu/ethualizer/blob/master/backnd.js

      tradeEvent = contractIns.Trade({}, {fromBlock: '4221476', toBlock: 'latest'});

      tradeEvent.watch(function (error, eventResult) {
          if (error) {
              console.error(error);
          } else {
              loco.play();
              console.log(JSON.stringify(eventResult, null, 4));
          }

I am returned results by the watch callback but blocknumber and other hashes and indexes are 0, although args seem genuine, I suspect I am looking at pending transactions

{
    "address": "0x8d12a197cb00d4747a1fe03395095ce2a5cc6819",
    "blockNumber": 0,
    "transactionHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "transactionIndex": 0,
    "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "logIndex": 0,
    "removed": false,
    "event": "Trade",
    "args": {
        "tokenGet": "0x0000000000000000000000000000000000000000",
        "amountGet": "3909184320983949755",
        "tokenGive": "0xe41d2489571d322189246dafa5ebde1f4699f498",
        "amountGive": "4.093386723543402884816e+21",
        "get": "0x798888341bfc01b30196091d27613fc6c68df159",
        "give": "0xafe15d1c5baab8f6fc9ba107a90a5729964ea14c"
    }
}

I can get the current latest block and interact with getters in the contract, I am using a geth lightnode in rpc mode to connect, so no connectivity problems.

other details : OS: Ubuntu 17.04

Edit: improved question using @farhankhwaja 's answer.

0

I think, you have missed something in here. I was able to capture the EVENT of my contract which I deployed on the TestNet.

Requirements

1. ABI - The contract ABI
2. Contract Address 
3. Web3js

Code

var myContractInstance = web3.eth.contract(JSON.parse(*<ABI>*)).at(*<CONTRAC_ADDRESS>*);

// Watching for MyEvent
var myEvent = myContractInstance.MyEvent({}, {fromBlock: '0', toBlock: 'latest'});

myEvent.get(function (error, eventResult) {
    if (error) {
         console.error(error);
    }
    else {
        loco.play();
        console.log(JSON.stringify(eventResult, null, 4));
    }
});

The above code if executed, will return you all the transactions in which the Event was called.

Example Transaction

{
        "address": "0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9",
        "blockNumber": 1495157,
        "transactionHash": "0x41fe9e995dba27c422ac5d0e9f1c8360ac512c3767c2217a0e729ed0b6098aa6",
        "transactionIndex": 0,
        "blockHash": "0x833c293455edb27c266fc2a0fbdab97431137c2f3d690c19835ddcf59ed4fe8a",
        "logIndex": 0,
        "removed": false,
        "event": "MyEevent",
        "args": {
            "_from": "0xb1aa0ac057639e534a89b095853befc4d6d264cf",
            "_to": "0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9",
            "_value": "1",
            "_tokenAddress": "0x85c02a9957f87445298eadffce717b7d256d6542",
            "_tokenName": "CC Series",
            "_tokenSymbol": "CC"
        }
}

Let me know if this doesn't give you the desired result.

5
  • my code is at github.com/praneethmendu/ethualizer/blob/master/backnd.js . I can get latest block and interact with getters, so requirements are taken care of. Despite using your code I still get results as shown in the question with block number, hashes and index as 0. I am watching for 'trade' event calls by EtherDelta. So I am working with main net. I suspect I am listening for 'pending' events instead of 'latest' transactions Aug 31 '17 at 2:24
  • @praneethmendu I ran your code and I was able to get the logs for the event. Some questions: 1. Is your Client 'geth/parity' sync with the MainNet? What is the output when your run web3.eth.blockNumber after connecting to your Client. The value/Output of the above command should be the block number being shown on EtherScan Sep 1 '17 at 17:35
  • I'm using : geth --syncmode "light" --cache=1024 -rpc --rpcapi="db,eth,net,web3,personal,web3" and I manage to get the latest block alright Sep 2 '17 at 5:33
  • This may be because of running geth in light mode ?? Sep 2 '17 at 5:47
  • I think you will need to use "fast".**Full Sync:** Gets the block headers, the block bodies, and validate every element from genesis block. Fast Sync: Gets the block headers, the block bodies, it performs no validation until current block - 1024. Then it gets a snap shot state and goes like a full synchronization. Light Sync: Gets only the current state. To verify elements, it needs to ask to full (archive) nodes for the corresponding tree leaves. Note: with the above description you will need to use fast/full Sep 3 '17 at 18:14

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.