0

I am newbie at Truffle environment. I built a new smart contract. Now I am trying to test this in truffle environment. I digged web for solving this problem but couldn't find any solution :(

Question

Is there any possible way to get output in my terminal with JSON-RPC(http post)?

JSON-RPC

$ curl -s -X POST --data '{
        "jsonrpc": "2.0",
        "method": "eth_sendTransaction",
        "params": [
            {
                "from": "0xAc582e97209b67BeF04a3d3d5121131835105df9",
                "to": "0x5614A60dF0C6FB8c6EB6e4Ba253D1CC59A2b6BF9",
                "data": "0x7fffb7bd"
            }
        ],
        "id": 1
    }' -H "Content-Type:application/json" http://192.168.0.100:7545

Above code is about call function, HelloWorld().

HelloWorld code

I made test code for asking in this community

function HelloWorld() public view returns (bytes4) {
    return 0x12345678;
}

The keccak value of HelloWorld() is 0x7fffb7bdf7d16635144da549e9a4eedff43ed43d64e49e18d7e365f9e5521232. So, the data in param, 0x7fffb7bd, is right. And also, I can see the transaction is well done in Ganache.

Return

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "0x6deeae5f09593e8c27fc1fb8353d5cef1124dbc5491c206f8150f7aa7e2253f5"
}

I only get the block hash. Not return value.

What is problem?

I expect that there is output like Remixd. In remixd, which is one of the famous solidity web IDE, shows output. Like below.

status             undefined
transaction hash   0x0341a3c3f9c904a55f5ae321e8b9a9332304b518aa2a201c92135aabff9295fb
from               0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
to                 0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47
execution cost     21435 gas
hash               0x0341a3c3f9c904a55f5ae321e8b9a9332304b518aa2a201c92135aabff9295fb
input              0x7fffb7bd
decoded input      {}
decoded output     {"0": "bytes4: 0x12345678"}
logs               []

As you can see, there is decoded output and this is what I want to see in my terminal.

How can I get output in my terminal?

2
  • Can you try querying http://127.0.0.1:7545?
    – Ismael
    Nov 6, 2021 at 6:04
  • @Ismael Sorry for late reply. My truffle server is on another computer. So, I had to query 192.168.0.100:7545. And also, I can see that transaction works. But I couldn't find where is the output.. :(
    – TyeolRik
    Nov 7, 2021 at 7:51

1 Answer 1

0

The problem is that you are calling eth_sendTransaction. To execute a view function use eth_call instead.

curl -X POST --data '{
        "jsonrpc": "2.0",
        "method": "eth_call",
        "params": [
            {
                "from": "0xAc582e97209b67BeF04a3d3d5121131835105df9",
                "to": "0x5614A60dF0C6FB8c6EB6e4Ba253D1CC59A2b6BF9",
                "data": "0x7fffb7bd"
            }
        ],
        "id": 1
    }' -H "Content-Type:application/json" http://192.168.0.100:7545
1
  • Oh my god... I found that this works. Thanks. I slightly understand how to get returns with eth_transaction (for writing blocks). I should use event :(
    – TyeolRik
    Nov 9, 2021 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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