Ethereum / Solidity getting smartcontract events in the geth console

Viewed 883

So I tried to retrieve the events generated by my smartcontract

var abi = [{
  "constant": false,
  "inputs": [{
    "name": "_value",
    "type": "int32"
  }],
  "name": "changeLowerTrigger",
  "outputs": [],
  "payable": false,
  "type": "function"
}, {
  "constant": true,
  "inputs": [],
  "name": "metric",
  "outputs": [{
    "name": "name",
    "type": "string",
    "value": "place_holder_metric_name_to_be_autogenerated"
  }, {
    "name": "value",
    "type": "int32",
    "value": "7"
  }],
  "payable": false,
  "type": "function"
}, {
  "constant": false,
  "inputs": [{
    "name": "_value",
    "type": "int32"
  }],
  "name": "changeUpperTrigger",
  "outputs": [],
  "payable": false,
  "type": "function"
}, {
  "constant": false,
  "inputs": [{
    "name": "_value",
    "type": "int32"
  }],
  "name": "update",
  "outputs": [],
  "payable": false,
  "type": "function"
}, {
  "anonymous": false,
  "inputs": [{
    "indexed": false,
    "name": "_value",
    "type": "int32"
  }],
  "name": "ValueChanged",
  "type": "event"
}, {
  "anonymous": false,
  "inputs": [{
    "indexed": false,
    "name": "_alarm",
    "type": "string"
  }, {
    "indexed": false,
    "name": "_value",
    "type": "int32"
  }],
  "name": "Alarm",
  "type": "event"
}]
var MyContract = web3.eth.contract(abi);

var myContractInstance = MyContract.at(
  '0x3B03c46Dfc878FeF9fAe8de4E32a6718f2E250e9');

var events = myContractInstance.allEvents();

// watch for changes
events.watch(function(error, event) {
  if (!error)
    console.log(event);
});

// Or pass a callback to start watching immediately
var events = myContractInstance.allEvents(function(error, log) {
  console.log(err, log);
});

But it returns only:

> events
{
  callbacks: [function(error, log)],
  filterId: "0xd6af6f5a7273fe21452f00c4682456",
  getLogsCallbacks: [],
  implementation: {
    getLogs: function(),
    newFilter: function(),
    poll: function(),
    uninstallFilter: function()
  },
  options: {
    address: "0x3B03c46Dfc878FeF9fAe8de4E32a6718f2E250e9",
    from: undefined,
    fromBlock: undefined,
    to: undefined,
    toBlock: undefined,
    topics: []
  },
  pollFilters: [],
  requestManager: {
    polls: {
      0xd6af6f5a7273fe21452f00c4682456: {
        data: {...},
        id: "0xd6af6f5a7273fe21452f00c4682456",
        callback: function(error, messages),
        uninstall: function()
      }
    },
    provider: {
      newAccount: function(),
      send: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
      sendAsync: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
      sign: 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(callback),
  watch: function(callback)
}

But what I want, is the events shown in the next image at the very bottom(e.g.Value Changed value:7): enter image description here

Since the events are displayed in the ETH-Wallet there should be a way. I rly just want a way to get the latest events in the geth console (or sth similare). Thanks for any help I'm kinda lost and having some of the worst googling of my life.

1 Answers

All you need to do is to call get() on the result object you've got and posted in your answer. Its described in official documentation and can be found here

Related