以太坊/Solidity:在geth控制台中获取智能合约事件

4

我尝试检索由我的智能合约生成的事件

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);
});

但它只返回:

> 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)
}

但我想要的是在下图底部显示的事件(例如:值更改值:7): enter image description here 由于这些事件显示在ETH钱包中,应该有一种方法。我只是想要在geth控制台中获取最新的事件(或类似的内容)。感谢任何帮助,我有点迷失,正在经历着我生命中最糟糕的搜索。
1个回答

1
你只需要在答案中调用你得到并发布的结果对象上的get()方法。它在官方文档中有描述,可以在这里找到。

最终找到了一个API(或其他东西),但是很高兴在这么长时间后看到了答案^^ - SLuck

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接