0

According to https://web3py.readthedocs.io/en/stable/contracts.html#web3.contract.ContractEvents.myEvent

web3 allows to extract the pertinent logs from a transaction receipt:

tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
rich_logs = contract.events.myEvent().processReceipt(tx_receipt)
rich_logs[0]['args']
    {'myArg': 12345}

but when using this code on geth console I got this error:

receipt = web3.eth.getTransactionReceipt("0x38b269e2fd7d8a2d8c814749ee252d98eaabe908203315c587e46f44a8b172d4")
erc20.events.Transfer().processReceipt(receipt)
    TypeError: Cannot access member 'Transfer' of undefined

being "Transfer" the event to query and erc20 a valid deployed contract

The value for erc20.events is

undefined

nevertheless erc20 seems ok:

erc20
{
  abi: [{
      constant: true,
      inputs: [],
      name: "name",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}],
      name: "approve",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "totalSupply",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}, {...}],
      name: "transferFrom",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "decimals",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "initialSupply",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}],
      name: "mint",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "standard",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [],
      name: "halt",
      outputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [{...}],
      name: "balanceOf",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}],
      name: "updateOwner",
      outputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "operations",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "contractBalance",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "owner",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}],
      name: "transferOrigin",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "symbol",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}],
      name: "destroy",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: false,
      inputs: [{...}, {...}],
      name: "transfer",
      outputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [],
      name: "halted",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      constant: false,
      inputs: [],
      name: "unhalt",
      outputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [{...}, {...}],
      name: "allowance",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      inputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "constructor"
  }, {
      anonymous: false,
      inputs: [{...}, {...}, {...}],
      name: "Transfer",
      type: "event"
  }, {
      anonymous: false,
      inputs: [{...}, {...}, {...}],
      name: "Approval",
      type: "event"
  }, {
      anonymous: false,
      inputs: [{...}, {...}],
      name: "Mint",
      type: "event"
  }, {
      anonymous: false,
      inputs: [{...}, {...}],
      name: "Destroy",
      type: "event"
  }, {
      anonymous: false,
      inputs: [{...}, {...}, {...}],
      name: "Halt",
      type: "event"
  }],
  address: "0x88e726de6cbadc47159c6ccd4f7868ae7a037730",
  transactionHash: null,
  Approval: function(),
  Destroy: function(),
  Halt: function(),
  Mint: function(),
  Transfer: function(),
  allEvents: function(),
  allowance: function(),
  approve: function(),
  balanceOf: function(),
  contractBalance: function(),
  decimals: function(),
  destroy: function(),
  halt: function(),
  halted: function(),
  initialSupply: function(),
  mint: function(),
  name: function(),
  operations: function(),
  owner: function(),
  standard: function(),
  symbol: function(),
  totalSupply: function(),
  transfer: function(),
  transferFrom: function(),
  transferOrigin: function(),
  unhalt: function(),
  updateOwner: function()

How can I view transaction events for a given contract and txhash by using web3 on geth console? Thx!

2
  • Geth's console uses web3 v0.20 so you might to try the old syntax github.com/ethereum/wiki/wiki/JavaScript-API#contract-events, but I'm not sure that version supports processing receipts.
    – Ismael
    May 7, 2019 at 17:48
  • I've used this trick with v0.20 var allEvents = w3.myContract.allEvents(); var eventLog = allEvents.formatter(logEntry);. I'd check when I've time if that trick does work from the command line.
    – Ismael
    May 8, 2019 at 20:27

1 Answer 1

0

Transfer is an event of ERC-20 token having declaration as:

event Transfer(address indexed from, address indexed to, uint tokens);

You need to fire Transfer event by passing these three parameteres also.

1
  • Transfer event is fired because the transaction calls contract method transfer. I just need to get the event data recorded on the transaction to verify everything is working ok May 7, 2019 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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