Search code examples
nearprotocol

How to get all the Transactions from a block in NEAR?


I have tried out the Apis - https://docs.near.org/docs/api/rpc#changes-in-block but the experimental one does not seems to have long term support . Any Help please

I have set up a node as well but i am not finding the node Apis to query the node


Solution

  • Transactions are included in chunk, so you need chunks (amount of chunks corresponds the amount of shards).

    So basically you're getting the block https://docs.near.org/docs/api/rpc#block-details

    http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare method=block \
      params:='{
        "finality": "final"
      }'
    

    Picking all chunk_hash from result.chunks

    After that fetch each chunk

    https://docs.near.org/docs/api/rpc#chunk-details

    http post https://rpc.testnet.near.org jsonrpc=2.0 method=chunk params:='{"chunk_id": "71gaCoF2vgDp2td2BWemSfrQkPNEaXqEiybZpt1k3doZ"}' id=dontcare
    

    And in the result.transactions you can find all the transactions.