16

This question was asked by @Pablo Yabo in the comment section of the question How can I view The DAO proposals including the current voting status?.

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 information like this:

var theDAOInterfaceABI = [{ "constant": true, "inputs": [{ "name": "", "type": "uint256" }], "name": "proposals", "outputs": [{ "name": "recipient", "type": "address" }, { "name": "amount", "type": "uint256" }, { "name": "description", "type": "string" }, { "name": "votingDeadline", "type": "uint256" }, { "name": "open", "type": "bool" }, { "name": "proposalPassed", "type": "bool" }, { "name": "proposalHash", "type": "bytes32" }, { "name": "proposalDeposit", "type": "uint256" }, { "name": "newCurator", "type": "bool" }, { "name": "yea", "type": "uint256" }, { "name": "nay", "type": "uint256" }, { "name": "creator", "type": "address" }], "type": "function" }, { "constant": true, "inputs": [], "name": "rewardAccount", "outputs": [{ "name": "", "type": "address" }], "type": "function" }, { "constant": true, "inputs": [], "name": "daoCreator", "outputs": [{ "name": "", "type": "address" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_proposalID", "type": "uint256" }, { "name": "_transactionData", "type": "bytes" }], "name": "executeProposal", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [], "name": "unblockMe", "outputs": [{ "name": "", "type": "bool" }], "type": "function" }, { "constant": true, "inputs": [], "name": "totalRewardToken", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "allowedRecipients", "outputs": [{ "name": "", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_to", "type": "address" }, { "name": "_amount", "type": "uint256" }], "name": "transferWithoutReward", "outputs": [{ "name": "success", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_recipient", "type": "address" }, { "name": "_amount", "type": "uint256" }, { "name": "_description", "type": "string" }, { "name": "_transactionData", "type": "bytes" }, { "name": "_debatingPeriod", "type": "uint256" }, { "name": "_newCurator", "type": "bool" }], "name": "newProposal", "outputs": [{ "name": "_proposalID", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "DAOpaidOut", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [], "name": "minQuorumDivisor", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_newContract", "type": "address" }], "name": "newContract", "outputs": [], "type": "function" }, { "constant": false, "inputs": [{ "name": "_recipient", "type": "address" }, { "name": "_allowed", "type": "bool" }], "name": "changeAllowedRecipients", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [], "name": "halveMinQuorum", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "paidOut", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_proposalID", "type": "uint256" }, { "name": "_newCurator", "type": "address" }], "name": "splitDAO", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": true, "inputs": [], "name": "DAOrewardAccount", "outputs": [{ "name": "", "type": "address" }], "type": "function" }, { "constant": true, "inputs": [], "name": "proposalDeposit", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [], "name": "numberOfProposals", "outputs": [{ "name": "_numberOfProposals", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [], "name": "lastTimeMinQuorumMet", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_toMembers", "type": "bool" }], "name": "retrieveDAOReward", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [], "name": "receiveEther", "outputs": [{ "name": "", "type": "bool" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "_proposalID", "type": "uint256" }], "name": "getNewDAOAddress", "outputs": [{ "name": "_newDAO", "type": "address" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_proposalID", "type": "uint256" }, { "name": "_supportsProposal", "type": "bool" }], "name": "vote", "outputs": [{ "name": "_voteID", "type": "uint256" }], "type": "function" }, { "constant": false, "inputs": [], "name": "getMyReward", "outputs": [{ "name": "_success", "type": "bool" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "rewardToken", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_from", "type": "address" }, { "name": "_to", "type": "address" }, { "name": "_amount", "type": "uint256" }], "name": "transferFromWithoutReward", "outputs": [{ "name": "success", "type": "bool" }], "type": "function" }, { "constant": false, "inputs": [{ "name": "_proposalDeposit", "type": "uint256" }], "name": "changeProposalDeposit", "outputs": [], "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }], "name": "blocked", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "constant": true, "inputs": [], "name": "curator", "outputs": [{ "name": "", "type": "address" }], "type": "function" }, { "constant": true, "inputs": [{ "name": "_proposalID", "type": "uint256" }, { "name": "_recipient", "type": "address" }, { "name": "_amount", "type": "uint256" }, { "name": "_transactionData", "type": "bytes" }], "name": "checkProposalCode", "outputs": [{ "name": "_codeChecksOut", "type": "bool" }], "type": "function" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "recipient", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "newCurator", "type": "bool" }, { "indexed": false, "name": "description", "type": "string" }], "name": "ProposalAdded", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "position", "type": "bool" }, { "indexed": true, "name": "voter", "type": "address" }], "name": "Voted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "result", "type": "bool" }, { "indexed": false, "name": "quorum", "type": "uint256" }], "name": "ProposalTallied", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "_newCurator", "type": "address" }], "name": "NewCurator", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "_recipient", "type": "address" }, { "indexed": false, "name": "_allowed", "type": "bool" }], "name": "AllowedRecipientChanged", "type": "event" }];
var theDAOAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";

var theDAOInterface = web3.eth.contract(theDAOInterfaceABI).at(theDAOAddress);
var theDAOVotedEvent = theDAOInterface.Voted({}, { fromBlock: 1594771, toBlock: 'latest' });
var i = 0;
theDAOVotedEvent.watch(function (error, result) {
    console.log(i++ + ": " + JSON.stringify(result));
});

Output in Geth console:

0: ...
...
1386: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"3","voter":"0x89dbadfc48054057b6c9c378f6edf9d15d8b1d68"},"blockHash":"0x8de0d6d13909ff5360aa9cff37de4e5395179dc24d0f04a92140c767637acc31","blockNumber":1630418,"event":"Voted","logIndex":0,"transactionHash":"0x5ff6ab2d46ad270503c55923b14fb431514efeb2d3e9b0140bf2ee20677c06cc","transactionIndex":0}
1387: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0xcd0a161bc367ae0927a92aac9cf6e5086714efca"},"blockHash":"0x8de0d6d13909ff5360aa9cff37de4e5395179dc24d0f04a92140c767637acc31","blockNumber":1630418,"event":"Voted","logIndex":1,"transactionHash":"0x50425d5be9aabb4186a90ae4461880b8e55f082f01bb48368b07504284b6798d","transactionIndex":1}
1388: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0x89dbadfc48054057b6c9c378f6edf9d15d8b1d68"},"blockHash":"0x8a520b39314bfa8ccfad64dc7d16c02ef5870db765f1b60bd04d49c3bcac4543","blockNumber":1630422,"event":"Voted","logIndex":0,"transactionHash":"0x51f31081c6cf9ae8a9b183aecd3aee8381eeae0933327c10fb3669faad1b133d","transactionIndex":0}
1389: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x89dbadfc48054057b6c9c378f6edf9d15d8b1d68"},"blockHash":"0xb652a73243f01635b8292beb88a6865f160a82efc04823c12e5a6cd0b3f75d7c","blockNumber":1630438,"event":"Voted","logIndex":0,"transactionHash":"0xc35e484949863c524be4a3419946f3f203f08124ca09bda61112c678cb744523","transactionIndex":0}
1390: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"5","voter":"0x1a51e74e25825b4ff2d0110ced7a46e0405259cd"},"blockHash":"0x9297abbd6a0eee95a51fc94b8856d8bdb4a9fe2dabd9c9308cbddec1cfd7c930","blockNumber":1630440,"event":"Voted","logIndex":0,"transactionHash":"0xb92834b3a18b65e990eb47fa6b215d3ab5fe074c92f76d679b2c6a4b40dea23a","transactionIndex":0}
1391: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"5","voter":"0xfe72c77797c23a22b606cd21630366d44a13761b"},"blockHash":"0x9297abbd6a0eee95a51fc94b8856d8bdb4a9fe2dabd9c9308cbddec1cfd7c930","blockNumber":1630440,"event":"Voted","logIndex":1,"transactionHash":"0x378fd02dec8c7b0a5920cb71e23b50f443b7a804968065f93c2d5a5c5c3df852","transactionIndex":1}
1392: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"5","voter":"0xe8be24f289443ee473bc76822f55098d89b91cc5"},"blockHash":"0x5baa04ff8fcc878aa9a4986ec5f197b2f3fca48b41c5bb9130fd358fb4c2500b","blockNumber":1630455,"event":"Voted","logIndex":0,"transactionHash":"0xa91d734fbd55f826c4b87e4dc904b5f1813c52f724cb5a5327654fcec4c5f70f","transactionIndex":1}
1393: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0xabe6d3b3b88277e5d9d58318be0d66896d806d92"},"blockHash":"0x637d893ec39e9a905d14c14cd6aee4e568dc6dbaa7f66c7ab48f6aa0838d0dd2","blockNumber":1630526,"event":"Voted","logIndex":0,"transactionHash":"0xaa28f6f9ecc6ef5132296f0587c2893a98fada046342dff45e4c9080e5558d90","transactionIndex":2}
1394: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0xabe6d3b3b88277e5d9d58318be0d66896d806d92"},"blockHash":"0xda2168aaf754bfca5c352cbf8c4d799f7273c789813a4e62920041b8892b5c71","blockNumber":1630534,"event":"Voted","logIndex":0,"transactionHash":"0x22a6ef6405438a236fbedc92970656294f5471ef5084945d9a73267287ec78e8","transactionIndex":1}
1395: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"5","voter":"0x9c42e0a1371b1b1c907540277a11f7728e7a55cb"},"blockHash":"0x682ba2d04c04e78fde0917d48e193232668465e6d16f4559aefce6017d2af1fa","blockNumber":1630584,"event":"Voted","logIndex":0,"transactionHash":"0x4a720cf5fa7734f81716c0bbbeb6b05c76ca9e17b3a7f68fbd0b010f90ea19db","transactionIndex":2}
1396: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x9c42e0a1371b1b1c907540277a11f7728e7a55cb"},"blockHash":"0x682ba2d04c04e78fde0917d48e193232668465e6d16f4559aefce6017d2af1fa","blockNumber":1630584,"event":"Voted","logIndex":1,"transactionHash":"0x0abb2eb5df7f409c4eecd35c9b46b283671a1ede9256637f313c2a6444ee9bb9","transactionIndex":4}
1397: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"5","voter":"0xc4e19f0a62a1d3bc6a53ba6c8c62d756aa735858"},"blockHash":"0xe06ec65d4c2d2641216e0c5d3fd0d74225421c795aa33bf6f4ef2ef421e51bf7","blockNumber":1630587,"event":"Voted","logIndex":2,"transactionHash":"0x44f297b84a22c5dc3ea2d48367e990b0a2de132df01789a6d7de33e0a8621a8c","transactionIndex":15}
1398: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0xc4e19f0a62a1d3bc6a53ba6c8c62d756aa735858"},"blockHash":"0x9b10dbbdcff964636fcdcb9c2456c66e3e11498dd6b37935761a6c0cedcb700c","blockNumber":1630588,"event":"Voted","logIndex":0,"transactionHash":"0x6e310b7fcb24eef068f123712eda95e90e76c35047c3ec85941e2aeb43c2ee2e","transactionIndex":2}
1399: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x15914fbb60a61dd8d277a35063e3f3fa7e8dce7f"},"blockHash":"0xc22a3dd53e6c903e004dc3ff890d10535f8b4db76fa16611defc583246f1253c","blockNumber":1630678,"event":"Voted","logIndex":0,"transactionHash":"0x341c98824de2780171ad2292b6796bea7ef1e9fe83b29082128c8b55fdcade99","transactionIndex":4}
1400: {"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"11","voter":"0x15914fbb60a61dd8d277a35063e3f3fa7e8dce7f"},"blockHash":"0x711f96cb919f3ae33257aea2109289872eeb99bf5f7e847f6aab82dbaee1c2e8","blockNumber":1630681,"event":"Voted","logIndex":0,"transactionHash":"0x6fb6766f3b10c0e2dcb71a739affdb0e9435af5194c7817ff66342c7385e696a","transactionIndex":0}
{
  callbacks: [function(error, result), function(error, result)],
  filterId: "0x7e76b6fdb1c1d51593815473e094c3a5",
  getLogsCallbacks: [],
  implementation: {
    getLogs: function(),
    newFilter: function(),
    poll: function(),
    uninstallFilter: function()
  },
  options: {
    address: "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
    from: undefined,
    fromBlock: "0x185593",
    to: undefined,
    toBlock: "latest",
    topics: ["0x86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae0", null, null]
  },
  pollFilters: [],
  requestManager: {
    polls: {
      0x7e76b6fdb1c1d51593815473e094c3a5: {
        data: {...},
        id: "0x7e76b6fdb1c1d51593815473e094c3a5",
        callback: function(error, messages),
        uninstall: function()
      }
    },
    provider: {
      newAccount: function(),
      send: function(),
      sendAsync: function(),
      unlockAccount: function()
    },
    timeout: {},
    poll: function(),
    reset: function(keepIsSyncing),
    send: function(data),
    sendAsync: function(data, callback),
    sendBatch: function(data, callback),
    setProvider: function(p),
    startPolling: function(data, pollId, callback, uninstall),
    stopPolling: function(pollId)
  },
  formatter: function(),
  get: function(callback),
  stopWatching: function(),
  watch: function(callback)
}

It works perfectly, it recalls all events from the specified block interval (here from block 1594771 to latest).

  • @Pablo Yabo, I tried using your modified code, but am still not getting the events consistently. Could you please add the full instructions you are using including some of the sample output. Thanks. – Bokky WeAreAllAssange PooBah Jun 2 '16 at 13:42
  • Check the new code, it was incomplete. Now, I tested the whole thing in Geth console and I got the same output there. – Pablo Yabo Jun 2 '16 at 15:01
  • How could I ignore getting the output { callbacks: filterId: ... watch: function(callback) } and only get the logs. @Pablo Yabo – alper Jun 3 '17 at 15:03
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":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"},{"name":"description","type":"string"},{"name":"votingDeadline","type":"uint256"},{"name":"open","type":"bool"},{"name":"proposalPassed","type":"bool"},{"name":"proposalHash","type":"bytes32"},{"name":"proposalDeposit","type":"uint256"},{"name":"newCurator","type":"bool"},{"name":"yea","type":"uint256"},{"name":"nay","type":"uint256"},{"name":"creator","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"minTokensToCreate","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"rewardAccount","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[],"name":"daoCreator","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"divisor","outputs":[{"name":"divisor","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"extraBalance","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proposalID","type":"uint256"},{"name":"_transactionData","type":"bytes"}],"name":"executeProposal","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[],"name":"unblockMe","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"totalRewardToken","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"actualBalance","outputs":[{"name":"_actualBalance","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"closingTime","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"allowedRecipients","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferWithoutReward","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[],"name":"refund","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_description","type":"string"},{"name":"_transactionData","type":"bytes"},{"name":"_debatingPeriod","type":"uint256"},{"name":"_newCurator","type":"bool"}],"name":"newProposal","outputs":[{"name":"_proposalID","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"DAOpaidOut","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"minQuorumDivisor","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_newContract","type":"address"}],"name":"newContract","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"address"},{"name":"_allowed","type":"bool"}],"name":"changeAllowedRecipients","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[],"name":"halveMinQuorum","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"paidOut","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proposalID","type":"uint256"},{"name":"_newCurator","type":"address"}],"name":"splitDAO","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"DAOrewardAccount","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[],"name":"proposalDeposit","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"numberOfProposals","outputs":[{"name":"_numberOfProposals","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"lastTimeMinQuorumMet","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_toMembers","type":"bool"}],"name":"retrieveDAOReward","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[],"name":"receiveEther","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"isFueled","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_tokenHolder","type":"address"}],"name":"createTokenProxy","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[{"name":"_proposalID","type":"uint256"}],"name":"getNewDAOAddress","outputs":[{"name":"_newDAO","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proposalID","type":"uint256"},{"name":"_supportsProposal","type":"bool"}],"name":"vote","outputs":[{"name":"_voteID","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"getMyReward","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"rewardToken","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFromWithoutReward","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proposalDeposit","type":"uint256"}],"name":"changeProposalDeposit","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"blocked","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"curator","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[{"name":"_proposalID","type":"uint256"},{"name":"_recipient","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_transactionData","type":"bytes"}],"name":"checkProposalCode","outputs":[{"name":"_codeChecksOut","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"privateCreation","outputs":[{"name":"","type":"address"}],"type":"function"},{"inputs":[{"name":"_curator","type":"address"},{"name":"_daoCreator","type":"address"},{"name":"_proposalDeposit","type":"uint256"},{"name":"_minTokensToCreate","type":"uint256"},{"name":"_closingTime","type":"uint256"},{"name":"_privateCreation","type":"address"}],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"FuelingToDate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"CreatedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Refund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"proposalID","type":"uint256"},{"indexed":false,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"newCurator","type":"bool"},{"indexed":false,"name":"description","type":"string"}],"name":"ProposalAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"proposalID","type":"uint256"},{"indexed":false,"name":"position","type":"bool"},{"indexed":true,"name":"voter","type":"address"}],"name":"Voted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"proposalID","type":"uint256"},{"indexed":false,"name":"result","type":"bool"},{"indexed":false,"name":"quorum","type":"uint256"}],"name":"ProposalTallied","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_newCurator","type":"address"}],"name":"NewCurator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_recipient","type":"address"},{"indexed":false,"name":"_allowed","type":"bool"}],"name":"AllowedRecipientChanged","type":"event"}];
undefined
> var theDAOAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";
undefined
> var theDAO = web3.eth.contract(theDAOABI).at(theDAOAddress);
undefined
> var theDAOVotedEvent = theDAO.Voted({}, {fromBlock: 1614771, toBlock: 'latest'});
undefined
> theDAOVotedEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
{
  callbacks: [function(error, result)],
  filterId: "0x5d0947e08a4e08102302bf0ca3352c91",
  getLogsCallbacks: [],
  implementation: {
    getLogs: function(),
    newFilter: function(),
    poll: function(),
    uninstallFilter: function()
  },
  options: {
    address: "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
    from: undefined,
    fromBlock: undefined,
    to: undefined,
    toBlock: undefined,
    topics: ["0x86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae0", null, null]
  },
  pollFilters: [],
  requestManager: {
    polls: {
      0x5d0947e08a4e08102302bf0ca3352c91: {
        data: {...},
        id: "0x5d0947e08a4e08102302bf0ca3352c91",
        callback: function(error, messages),
        uninstall: function()
      }
    },
    provider: {
      newAccount: function(),
      send: function(),
      sendAsync: function(),
      unlockAccount: function()
    },
    timeout: {},
    poll: function(),
    reset: function(keepIsSyncing),
    send: function(data),
    sendAsync: function(data, callback),
    sendBatch: function(data, callback),
    setProvider: function(p),
    startPolling: function(data, pollId, callback, uninstall),
    stopPolling: function(pollId)
  },
  formatter: function(),
  get: function(callback),
  stopWatching: function(),
  watch: function(callback)
}
...
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x3d0e8b47fbb03727c72585fbe2fd5f25c69c03f2b832753567c2309f1ecb3b2a","blockNumber":1614808,"event":"Voted","logIndex":0,"transactionHash":"0x0060654808a2dee9710fa01e26adb46e77df03c17e453e8fddc8749269ffad92","transactionIndex":1}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"11","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x607d940ebbbb17e6d5c3c8a871cd4783b271ddf71f4aeb83dbcdcaf8ce2154d9","blockNumber":1614812,"event":"Voted","logIndex":1,"transactionHash":"0x6b5cab6f7987d7283fdde051c76ace98c9f080bda6dbdf720689fc0c3958005b","transactionIndex":6}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"11","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x69be968ce90c7e910c149cc80ab1e5f2ae6bdb45f142ee0e6fa181be9d1e106e","blockNumber":1614812,"event":"Voted","logIndex":0,"transactionHash":"0x6b5cab6f7987d7283fdde051c76ace98c9f080bda6dbdf720689fc0c3958005b","transactionIndex":2}
...



Filtering Events

Here is the DAOInterface.Voted event definition from EtherScan.io - The DAO - Source Code:

event Voted(uint indexed proposalID, bool position, address indexed voter);

And here is a sample of commands using the voter and proposalID fields to filter for particular events:

// Find all Voted events from one address
var theDAOVotedEvent = theDAO.Voted({voter: "0x8063379a7bf2cb923a84c5093e68dac7f75481c5"}, {fromBlock: 1614771, toBlock: 'latest'});
theDAOVotedEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x8063379a7bf2cb923a84c5093e68dac7f75481c5"},"blockHash":"0x95d70e74b051efdea1de5c0750eaba0c6314bec7c1d460cc0cfd8607e277ad17","blockNumber":1632445,"event":"Voted","logIndex":1,"transactionHash":"0x6eaefad5a1357e30a142e0300a2f227331c173dd0b52aba6c41d59d917c623ab","transactionIndex":1}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0x8063379a7bf2cb923a84c5093e68dac7f75481c5"},"blockHash":"0x999eb317dda8b3355984dd78402e7c5cd6162e37f33d7a1c0d46b5270ff731b3","blockNumber":1632885,"event":"Voted","logIndex":0,"transactionHash":"0x5ecc44eb85c4b20fe115f2a8aaa862b7fd8365769e6e69f802b0af1aad452fe0","transactionIndex":0}

// Find all Voted events from a list of addresses
var theDAOVotedEvent = theDAO.Voted({voter: ["0x8063379a7bf2cb923a84c5093e68dac7f75481c5", "0x365968a0747edc66e4ae3b0a6c065de903ee4ae9"]}, {fromBlock: 1614771, toBlock: 'latest'});
theDAOVotedEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x8063379a7bf2cb923a84c5093e68dac7f75481c5"},"blockHash":"0x95d70e74b051efdea1de5c0750eaba0c6314bec7c1d460cc0cfd8607e277ad17","blockNumber":1632445,"event":"Voted","logIndex":1,"transactionHash":"0x6eaefad5a1357e30a142e0300a2f227331c173dd0b52aba6c41d59d917c623ab","transactionIndex":1}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0x8063379a7bf2cb923a84c5093e68dac7f75481c5"},"blockHash":"0x999eb317dda8b3355984dd78402e7c5cd6162e37f33d7a1c0d46b5270ff731b3","blockNumber":1632885,"event":"Voted","logIndex":0,"transactionHash":"0x5ecc44eb85c4b20fe115f2a8aaa862b7fd8365769e6e69f802b0af1aad452fe0","transactionIndex":0}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x365968a0747edc66e4ae3b0a6c065de903ee4ae9"},"blockHash":"0x691bfffe628da1ba2c088236769acd81ca496a575fd31a4d1231cf849dc80b97","blockNumber":1632924,"event":"Voted","logIndex":3,"transactionHash":"0x7f060b7d08fc1a7093c2ff27df4c4389193c242cf5d14f2f4fe2188fb1710e2c","transactionIndex":4}

// Find all Voted events from a list of addresses for a particular proposalID
var theDAOVotedEvent = theDAO.Voted({voter: ["0x8063379a7bf2cb923a84c5093e68dac7f75481c5", "0x365968a0747edc66e4ae3b0a6c065de903ee4ae9"], proposalID: "17"}, {fromBlock: 1614771, toBlock: 'latest'});
theDAOVotedEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});

{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x8063379a7bf2cb923a84c5093e68dac7f75481c5"},"blockHash":"0x95d70e74b051efdea1de5c0750eaba0c6314bec7c1d460cc0cfd8607e277ad17","blockNumber":1632445,"event":"Voted","logIndex":1,"transactionHash":"0x6eaefad5a1357e30a142e0300a2f227331c173dd0b52aba6c41d59d917c623ab","transactionIndex":1}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"17","voter":"0x365968a0747edc66e4ae3b0a6c065de903ee4ae9"},"blockHash":"0x691bfffe628da1ba2c088236769acd81ca496a575fd31a4d1231cf849dc80b97","blockNumber":1632924,"event":"Voted","logIndex":3,"transactionHash":"0x7f060b7d08fc1a7093c2ff27df4c4389193c242cf5d14f2f4fe2188fb1710e2c","transactionIndex":4}



Reference

From JavaScript API - web3.eth.filter:

Object - A filter object with the following methods:

  • filter.get(callback): Returns all of the log entries that fit the filter.
  • filter.watch(callback): Watches for state changes that fit the filter and calls the callback. See this note for details.
  • filter.stopWatching()**: **Stops the watch and uninstalls the filter in the node. Should always be called once it is done.
  • Thank you for the code. With this code I get the new votes but I'm not getting the new ones. If you see in the response it says: fromBlock: undefined, to: undefined, toBlock: undefined – Pablo Yabo May 31 '16 at 14:27
  • You are getting the new votes, but not the old votes? Try setting the fromBlock parameter. – Bokky WeAreAllAssange PooBah May 31 '16 at 14:29
  • I did, I tried 0, 1000000, 1600000 and more but it always says toBlock: undefined and only new votes are reported. Any ideas? – Pablo Yabo May 31 '16 at 14:35
  • 2
    I tried using get() but could not get the results back. If I work it out, I'll update this page. – Bokky WeAreAllAssange PooBah May 31 '16 at 15:07
  • I'll try it. Where do you get this documentation? – Pablo Yabo May 31 '16 at 15:11

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.