Skip to content

Instantly share code, notes, and snippets.

@cordt-sei
Created October 22, 2024 16:36
Show Gist options
  • Save cordt-sei/904033ddd45f8a58ba3d40aeb1acf7e8 to your computer and use it in GitHub Desktop.
Save cordt-sei/904033ddd45f8a58ba3d40aeb1acf7e8 to your computer and use it in GitHub Desktop.

Overview: Querying Transaction Data on Sei EVM and Tendermint

This guide covers how to query transaction data on Sei’s blockchain using both Tendermint-based and EVM-based methods. The examples demonstrate working queries and sample responses, showing how the same transaction can be viewed from different perspectives. Here, the two transaction hashes we use represent the same transaction: one is the EVM-compatible hash, while the other is the Tendermint (Cosmos) hash. Both provide insights into the same event but from the unique contexts of their respective environments.

1. Tendermint REST API (cosmos/tx/v1beta1/txs/{hash})

  • Endpoint: {$SEIREST}/cosmos/tx/v1beta1/txs/{transaction_hash}
  • Use Case: Retrieve comprehensive transaction details in a Cosmos-specific format, including message data, events, and gas usage.

Working Query Example:

curl -s "{$SEIREST}/cosmos/tx/v1beta1/txs/63FE5686A27D1C7144CF168F4CCDC062A521F6AE33783B0FA6FD2E5ED2F44DC2" | jq

Example Response:

Click to expand
{
  "tx": {
    "body": {
      "messages": [
        {
          "@type": "/seiprotocol.seichain.evm.MsgEVMTransaction",
          "data": {
            "@type": "/seiprotocol.seichain.eth.DynamicFeeTx",
            "chain_id": "1329",
            "nonce": "29",
            "gas_tip_cap": "100000000000",
            "gas_fee_cap": "100000000000",
            "gas_limit": "81188",
            "to": "0xe70AAa288F801B208074171be87b804178Ce5d11",
            "value": "88000000000000000000",
            "data": "s3RoSQAAAAAAAAAAAAAAAHB38vjp0g1nzrrR+6/w4Z3fCCuoAAAAAAAAAAAAAAAAAAAA=",
            "v": null,
            "r": "BlIMxJG6NuOnnryNAVT08lfYPCTpkisrnHre0irkQrY=",
            "s": "B9MLiTBlGW5NsSjJISQOfqFFsNkY57088pPYRSDB5Pg="
          }
        }
      ],
      "memo": "",
      "timeout_height": "0"
    },
    "auth_info": {
      "fee": {
        "amount": [],
        "gas_limit": "0"
      }
    },
    "signatures": []
  },
  "tx_response": {
    "height": "110130949",
    "txhash": "63FE5686A27D1C7144CF168F4CCDC062A521F6AE33783B0FA6FD2E5ED2F44DC2",
    "code": 0,
    "data": "0AF1050A...",
    "raw_log": "[{\"events\":[{\"type\":\"coin_received\",...]}]",
    "logs": [
      {
        "msg_index": 0,
        "events": [
          {
            "type": "coin_received",
            "attributes": [
              {"key": "receiver", "value": "sei1uu9252y0sqdjpqr5zud7s7uqg9uvuhg3xqzjdm"},
              {"key": "amount", "value": "88000000usei"}
            ]
          },
          {
            "type": "message",
            "attributes": [
              {"key": "action", "value": "/seiprotocol.seichain.evm.MsgEVMTransaction"}
            ]
          }
        ]
      }
    ],
    "gas_wanted": "81188",
    "gas_used": "80287"
  }
}

Description:

  • Provides detailed transaction information, including the type, gas details, events, and any error codes.
  • Ideal for analyzing transaction specifics at the Tendermint/Cosmos level.

2. eth_getTransactionReceipt

  • Endpoint: https://evm-rpc.sei-apis.com
  • Use Case: Obtain EVM-compatible receipt details for a specific transaction, including logs, gas usage, and execution status.

Working Query Example:

curl -sX POST "https://evm-rpc.sei-apis.com" \
     -H "Content-Type: application/json" \
     -d '{
       "jsonrpc": "2.0",
       "method": "eth_getTransactionReceipt",
       "params": ["0x06d5af346c8469d6075c538830bdbac6dfc877a6089e297a4dfb36a70a63d19b"],
       "id": 1
     }' | jq

Example Response:

Click to expand
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "blockHash": "0x2c156d42561e934fdcca27aaeb80a43a5c0fe670373a9a5bc0f796685632a72f",
    "blockNumber": "0x6907705",
    "contractAddress": null,
    "cumulativeGasUsed": "0x0",
    "effectiveGasPrice": "0x174876e800",
    "from": "0x7367bdd3400dc445f19ebc07e6c4c8e863966963",
    "gasUsed": "0x1399f",
    "logs": [
      {
        "address": "0x7077f2f8e9d20d67cebad1fbaff0e19ddf082ba8",
        "topics": [
          "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
          "0x000000000000000000000000e70aaa288f801b208074171be87b804178ce5d11",
          "0x0000000000000000000000007367bdd3400dc445f19ebc07e6c4c8e863966963"
        ],
        "data": "0x000000000000000000000000000000000000000000000000000002bda534d3b9"
      }
    ],
    "status": "0x1",
    "to": "0xe70aaa288f801b208074171be87b804178ce5d11",
    "transactionHash": "0x06d5af346c8469d6075c538830bdbac6dfc877a6089e297a4dfb36a70a63d19b",
    "type": "0x2"
  }
}

Description:

  • Returns receipt details for a specific transaction, including emitted logs, contract addresses, gas usage, and the execution status.
  • Suitable for verifying logs and transaction outcomes in an EVM-compatible context.

3. Generic Log Query with eth_getLogs

  • Endpoint: https://evm-rpc.sei-apis.com
  • Use Case: Retrieve logs from a specified block range, allowing you to find all logs within a specific block without specifying addresses or topics.

Working Query Example:

curl -sX POST "https://evm-rpc.sei-apis.com" \
     -H "Content-Type: application/json" \
     -d '{
       "jsonrpc": "2.0",
       "method": "eth_getLogs",
       "params": [{
         "fromBlock": "0x6907705",
         "toBlock": "0x6907705"
       }],
       "id": 1
     }' | jq

Example Response:

Click to expand
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "address": "0x7077f2f8e9d20d67cebad1fbaff0e19ddf082ba8",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x000000000000000000000000e70aaa288f801b208074171be87b804178ce5d11",
        "0x0000000000000000000000007367bdd3400dc445f19ebc07e6c4c8e863966963"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000002bda534d3b9",
      "blockNumber": "0x6907705",
      "transactionHash": "0

x06d5af346c8469d6075c538830bdbac6dfc877a6089e297a4dfb36a70a63d19b",
      "logIndex": "0x0"
    },
    {
      "address": "0xe70aaa288f801b208074171be87b804178ce5d11",
      "topics": [
        "0x0b9c8304b83df3d2827b952a8e4c87faef3556dddcde57a47cb80f0c755606a5",
        "0x0000000000000000000000007077f2f8e9d20d67cebad1fbaff0e19ddf082ba8"
      ],
      "data": "0x0000000000000000000000007367bdd3400dc445f19ebc07e6c4c8e863966963000000000000000000000000000000000000000000000004b9086a6b20080000000000000000000000000000000000000000000000000000000002bda534d3b9",
      "blockNumber": "0x6907705",
      "transactionHash": "0x06d5af346c8469d6075c538830bdbac6dfc877a6089e297a4dfb36a70a63d19b",
      "logIndex": "0x1"
    }
  ]
}

Description:

  • Provides logs for all transactions within the specified block range.
  • Useful for finding events or logs across multiple contracts without pre-defining specific addresses or topics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment