2

I'm connecting to a testnet using a Geth node running version 1.8.8-stable, and also I'm using the web3j lib version 3.4.0.

I deployed a Smart Contract and also used the web3j wrapper tools to interact with the contract and everything looks like working.

What I want to do is to decode the information from newly mined blocks. i.e. I subscribe and I can retrieve all transaction from the newly mined blocks.

I know that a transaction is about my smart-contracts because the "to" address is the same in smart-contracts. But how can I recognize the functions that were called???

Sorry for my English, I hope that someone can help me. Here an example of the Transaction Receipt that I retrieve from a transaction hash. Is there any way to understand what function of the smart contract was called???

TransactionReceipt{ 

transactionHash='0x6583a913786bc0010937806c4a97e8fcac673b1cd9e25c79074df76ae235f4f5',

transactionIndex='0x0',

blockHash='0x624ed9afc8a45c0b79a1c471fe732d00b813cc476f264e9ada0d3a15a7cf6198'

blockNumber='0x5e4cf' 

cumulativeGasUsed='0x9495', 

gasUsed='0x9495', 

contractAddress='null', 

root='0x3a175640d6654236151ffc9f9afbd9087a656b2b46ead9df5587725a77d3bd7a',

status='null', 

from='0x145107ef476743eaabf8df07cefd47b17d87506c',

to='0x70104c2d70145d745ee9308e0ee428e1d96e6142', 

logs=[Log{removed=false, logIndex='0x0', transactionIndex='0x0', transactionHash='0x6583a913786bc0010937806c4a97e8fcac673b1cd9e25c79074df76ae235f4f5', blockHash='0x624ed9afc8a45c0b79a1c471fe732d00b813cc476f264e9ada0d3a15a7cf6198', blockNumber='0x5e4cf', address='0x70104c2d70145d745ee9308e0ee428e1d96e6142', data='0x0000000000000000000000000000000000000000000000000000000000000064', type='null', topics=[0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x000000000000000000000000145107ef476743eaabf8df07cefd47b17d87506c, 0x00000000000000000000000061259ec0cfc824e41b5ca2cc64f6453476b165b4]}],

logsBloom='0x00000000000008000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000040000000000080020000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000000000000000000000000000800010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000'
}
1
  • Thanks biplavo for the answer, I know about the possibility to use the event of a smart contract, but want I want i to read the information directly from the transaction. May 29, 2018 at 22:30

1 Answer 1

2

Events can be emitted from your smart contract function. Events provide the EVM logging facilities. You can emit such event when a function is called in your contract and in the Web3j you can subscribe or listen to these events so, you would exactly know which function has been called.

You might need to change your smart contract code to add events in required functions.

An example :

Solidity

event DoThis();
function doSomething() public returns (bool){
   emit DoThis();
   return true;
}

Web3j

contractInstance.DoThisEventObservable(null, DefaultBlockParameterName.LATEST).subscribe(response -> {
            // TODO : your task
            System.out.println("response.log = " + response.log);
        });

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.