AnswerBun.com

Viewing transaction events by using web3 on geth console

Ethereum Asked by Juan Ignacio Pérez Sacristán on January 1, 2022

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!

One Answer

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.

Answered by Prachi Sharma on January 1, 2022

Add your own answers!

Related Questions

Avoiding double spending in Plasma Cash

1  Asked on December 25, 2021

 

Filter past events with condition

0  Asked on December 25, 2021 by simon-bachmann

   

fatal error when try to serve geth in ipc

1  Asked on December 23, 2021

   

How long did a transaction spend in the mempool?

1  Asked on December 22, 2021 by jespern

     

Migrate contract from testnet to mainnet

2  Asked on December 20, 2021

 

Is there some possibility to listen MakerDAO’s LogNote events?

1  Asked on December 20, 2021 by svitlana-moiseyenko

     

Call a smart contract function when condition met

1  Asked on December 18, 2021 by yohjinakamoto

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP