4

Is there a command to enter into the terminal to check past transactions on the locally deployed ganache-cli blockchain? With ganache gui one gets the transactions button. Is there some similar functionality for ganache-cli or does one have to scroll? thanks in advance

vladimir
  • 228
  • 1
  • 5
GreyShadow94
  • 43
  • 1
  • 5

1 Answers1

1

You can use truffle console and web3-eth API:

# connect to 'development' network
truffle console

Get log of the latest transaction:

truffle(development)> await web3.eth.getPastLogs({})
[
  {
    logIndex: 0,
    transactionIndex: 0,
    transactionHash: '0x8d550f02c2ad9ce0770100ea35fddcb4239605338904999bac0b44ab98d47469',
    blockHash: '0x51cfc9b9fb563729ea9791258d172e2d7e15526fa39df3cc8002d8c1e124b023',
    blockNumber: 14,
    address: '0xc8474d35f43c485A193f4619AD5dfc13E6Ef7670',
    data: '0x0000000000000000000000000000000000000000000000000000000000000000',
    topics: [
      '0x6c0fa476682fe2e95bf3de06aae1b1660cd12883277ff64b03496b5e1a7d08dd',
      '0x000000000000000000000000000000000000000000000000000000006047e03d',
      '0x000000000000000000000000000000000000000000000000000000006047e040',
      '0x000000000000000000000000000000000000000000000000000000006047e041'
    ],
    type: 'mined',
    id: 'log_320edfe0'
  }
]

Get info about the n-th transaction in n-th block:

# get info about the first transaction on the 14th block

truffle(development)> await web3.eth.getTransactionFromBlock(14, 0) { hash: '0x8d550f02c2ad9ce0770100ea35fddcb4239605338904999bac0b44ab98d47469', nonce: 7, blockHash: '0x51cfc9b9fb563729ea9791258d172e2d7e15526fa39df3cc8002d8c1e124b023', blockNumber: 14, transactionIndex: 0, from: '0xc7815B5AA79E6A215131D633f40379459298D892', to: '0xc8474d35f43c485A193f4619AD5dfc13E6Ef7670', value: '0', gas: 6721975, gasPrice: '20000000000', input: '0xfed8d203000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000e636f6e74726f6c206e756d62657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087472616365206964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e696e766f696365206e756d626572000000000000000000000000000000000000', v: '0x26', r: '0xe3ee9a1bfca535a673618ed5fcac24ecf3f77d0aab04e6eaacc404d0f231b57f', s: '0x15bcb052913f4de6f9457bf9f1ff23ba35a33d11b777c41a74911bbdcc5b964b' }

take transaction-hash to get its receipt

truffle(development)> await web3.eth.getTransactionReceipt('0x8d550f02c2ad9ce0770100ea35fddcb4239605338904999bac0b44ab98d47469') { transactionHash: '0x8d550f02c2ad9ce0770100ea35fddcb4239605338904999bac0b44ab98d47469', transactionIndex: 0, blockHash: '0x51cfc9b9fb563729ea9791258d172e2d7e15526fa39df3cc8002d8c1e124b023', blockNumber: 14, from: '0xc7815b5aa79e6a215131d633f40379459298d892', to: '0xc8474d35f43c485a193f4619ad5dfc13e6ef7670', gasUsed: '0x21db2', cumulativeGasUsed: 138674, contractAddress: null, logs: [ { logIndex: 0, transactionIndex: 0, transactionHash: '0x8d550f02c2ad9ce0770100ea35fddcb4239605338904999bac0b44ab98d47469', blockHash: '0x51cfc9b9fb563729ea9791258d172e2d7e15526fa39df3cc8002d8c1e124b023', blockNumber: 14, address: '0xc8474d35f43c485A193f4619AD5dfc13E6Ef7670', data: '0x0000000000000000000000000000000000000000000000000000000000000000', topics: [Array], type: 'mined', id: 'log_320edfe0' } ], status: true, logsBloom: '0x00000000000000000400000000000000000000000800000000800800000000000004000000000000200000000000400000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000080000000000000000000000000000000000000002000000000000000000000000000000000100000000000000000000000' }


To decode TX data follow this answer How to decode input data from a transaction?.

vladimir
  • 228
  • 1
  • 5