XLeo
XLeo

Reputation: 21

How to get transactions invoked by smart contract from blockchain

I want to get all receipt records of some address (address A) from blockchain. I use web3.eth.getBlock and web3.eth.getTransaction to get all transactions related to A. But I find if ethers are transfered to address A by invoking 'A.send' or 'A.transfer' function in contract, I can only get a contract call transaction which from caller address to contract address. And I can't find relationship between this transaction and address A. Is there any way to get transactions invoked by contract for A? Thanks.

Upvotes: 2

Views: 4238

Answers (1)

carver
carver

Reputation: 2349

Short answer: listen to events instead of monitoring transactions.

Why can't I find the transactions "invoked by" the contract?

A contract does not invoke/create its own transaction (it doesn't have a private key to sign one). A contract can call other contracts during its own execution, as you've seen, but those calls are all executed as part of the same transaction.

The recommended way to discover executed function calls is to use events. If the contract you want to watch does not specify an event on the call you want to watch, you may be in for some heavy lifting: tracing every transaction's execution at the EVM level (something that big block explorers do to generate some of the extra info they provide).

If you are stuck tracing: you can find more about using ethereumjs-vm or geth's debug_traceTransaction on this Ethereum StackExchange Question about internal transactions.

Upvotes: 2

Related Questions