1

When I perform a contract function-call via Truffle, and then resolve the returned promise, I get something like this:

{
    "tx": "0x...",
    "receipt": {
        "transactionHash": "0x...",
        "transactionIndex": 0,
        "blockHash": "0x...",
        "blockNumber": 24,
        "gasUsed": 42860,
        "cumulativeGasUsed": 42860,
        "contractAddress": null,
        "logs": [
            {
                "logIndex": 0,
                "transactionIndex": 0,
                "transactionHash": "0x...",
                "blockHash": "0x...",
                "blockNumber": 24,
                "address": "0x...",
                "data": "0x...",
                "topics": [
                    "0x...",
                    "0x...",
                    "0x..."
                ],
                "type": "mined"
            }
        ],
        "status": "0x1",
        "logsBloom": "0x..."
    },
    "logs": [
        {
            "logIndex": 0,
            "transactionIndex": 0,
            "transactionHash": "0x...",
            "blockHash": "0x...",
            "blockNumber": 24,
            "address": "0x...",
            "type": "mined",
            "event": "Transfer",
            "args": {
                "from": "0x...",
                "to": "0x...",
                "value": "0"
            }
        }
    ]
}

I'm not really sure how exactly Truffle wraps web3.js in order to invoke contract functions, so I'm not really sure where to look in the web3.js documentation. But I am using Truffle v4.1.14, which relies on web3.js v0.18.4, and the docs for web3.js v0.x are kinda hard to read, so I searched in the docs for web3.js v1.x instead.

Now, I guess I should be looking into web3.eth.sendSignedTransaction, which returns:

A promise combined event emitter. Will be resolved when the transaction receipt is available.

So it seems that Truffle takes this receipt, and embeds it into a JSON object which contains the following additional fields:

  1. tx, which is the transaction hash, I suppose
  2. logs, which contains some or all of the receipt.logs, but decoded

So what exactly is going on here?

This new object is certainly not the receipt described in the docs.

Is there an official terminology for this, or is it just a "Truffle hack" designated to make my life easier decoding events?

Thank you.

1 Answer 1

1

Clearly truffle returns it's own object. It will surely contain the original web3 receipt which is labeled receipt because truffle uses web3 0.x as you mentioned. So the added attributes are nothing more than a way of truffle trying to make its framework better and keep the layer above web3.

I don't think there is a certain terminology for that object, or at least it will always be overshadowed by the transactionReceipt of Web3, hence the same name take for both.

4
  • But if I were to try to keep my test code compatible outside of truffle (for example, suppose I have some common JS utilities that I want to use for "realtime" interaction with the Ethereum network), then I should probably avoid relying on that additional layer, correct? Commented Nov 19, 2018 at 20:48
  • yes, or you could write separate testing utilities for truffle and for the outside of truffle. it is not that hard, considering it is just a json attribute away. Commented Nov 19, 2018 at 21:50
  • 1
    I decided that the name response would be suitable enough. Then I can refer to response.tx, response.logs, response.receipt, response.receipt.logs, etc. Commented Nov 20, 2018 at 7:58
  • BTW, would you have any idea how Truffle is able to extract the event name from the receipt? In the example above, it is in response.logs[0].event. Commented Nov 20, 2018 at 7:59

Your Answer

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

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