EOSIO/eosjs

How can I list the latest blocks and transactions?

jordigoyanes opened this issue · 11 comments

eos.getBlock() returns information for a specific block.
eos.getTransaction() returns information for a specific transaction.
eos.getTransactions() returns information for transactions from a specific account.

Can I get a list of the latest blocks and transactions using eosjs?

getInfo will give you the head block number.. You need to call getBlock(n) for each block to get all transactions.. In a few weeks I will be updating the API with dawn 3.0, maybe there is something new on the way. I have not checked on it recently.

@jordigoyanes please let me know if you need any additional feedback, if not I'll close this ticket in the next few days.

Closing this issue, assuming the user has gotten what they needed.

I can see in getBlock that it has all the transactions listed (in dawn3). So if this was a bug it will be fixed.

Confirmed .. the transactions were missing in dawn2 .

Dawn3 does not have a public testnet yet. But with my own eosiod running in docker, this is what I see:

> eos.getBlock(173)
api > http://127.0.0.1:8888/v1/chain/get_block {"block_num_or_id":173}
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }
> api < { previous: '000000ac2e618e0d8b726be6ab783a707ca78c72e2550984c59ca7633b369af5',
  timestamp: '2018-03-06T15:10:06.000',
  transaction_mroot: '44ca3a6a89a75ec90c3d7f21151052c97c318e8d9eadc878cfa25f36c23b5fe7',
  action_mroot: 'b6707ef19bba38dbd30ced5df0558ae820dce3dfc35337c74f675411dbb2dcb7',
  block_mroot: 'bb25f96a091c5c6aeb7c70d360bb8311df649dfb62b4061035255ba957e4c725',
  producer: 'eosio',
  new_producers: null,
  producer_signature: 'EOSK4yBTyc2vj78MQqUJ8yEuh9ZTSStkWhka2puw1d3inZKdURBCP8nXPA6ASG4ZcuBEgXLNBefVisobtxCj2gmz3bnz8gjqd',
  regions: [ { region: 0, cycles_summary: [Array] } ],
  input_transactions: 
   [ { signatures: [Array],
       compression: 'none',
       hex_data: '6baf9e5a0000ac008b726be60000000000010000001e4d75af460000000000a53176010000001e4d75af4600000000a8ed3232180000001e4d75af4600841316dd5100000443555200000000',
       data: [Object] },
     { signatures: [Array],
       compression: 'none',
       hex_data: '6baf9e5a0000ac008b726be60000000000010000001e4d75af46000000572d3ccdcd010000001e4d75af4600000000a8ed3232210000001e4d75af46000000008093dd7400e40b5402000000044355520000000000',
       data: [Object] },
     { signatures: [Array],
       compression: 'none',
       hex_data: '6baf9e5a0000ac008b726be60000000000010000001e4d75af46000000572d3ccdcd01000000008093dd7400000000a8ed323221000000008093dd740000008a4dd3505700e40b5402000000044355520000000000',
       data: [Object] } ],
  id: '000000ada96204d352fefe15e300dee94d98c1514616fdee6c6e7e6ad6083ba3',
  block_num: 173,
  ref_block_prefix: 369032786 }
> _.then(r => console.log(JSON.stringify(r, null, 2)))
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }
> {
  "previous": "000000ac2e618e0d8b726be6ab783a707ca78c72e2550984c59ca7633b369af5",
  "timestamp": "2018-03-06T15:10:06.000",
  "transaction_mroot": "44ca3a6a89a75ec90c3d7f21151052c97c318e8d9eadc878cfa25f36c23b5fe7",
  "action_mroot": "b6707ef19bba38dbd30ced5df0558ae820dce3dfc35337c74f675411dbb2dcb7",
  "block_mroot": "bb25f96a091c5c6aeb7c70d360bb8311df649dfb62b4061035255ba957e4c725",
  "producer": "eosio",
  "new_producers": null,
  "producer_signature": "EOSK4yBTyc2vj78MQqUJ8yEuh9ZTSStkWhka2puw1d3inZKdURBCP8nXPA6ASG4ZcuBEgXLNBefVisobtxCj2gmz3bnz8gjqd",
  "regions": [
    {
      "region": 0,
      "cycles_summary": [
        [
          {
            "read_locks": [],
            "write_locks": [
              {
                "account": "currency",
                "scope": "currency"
              },
              {
                "account": "currency",
                "scope": "exchange"
              },
              {
                "account": "currency",
                "scope": "initb"
              }
            ],
            "transactions": [
              {
                "status": "executed",
                "id": "47037ed4532086853a983004c43f33b238596eca30da73afa9105019ecd8060f"
              },
              {
                "status": "executed",
                "id": "d6cec747baec2d984cca2d740079aa10928f3ab962f99211f60888a49c6af212"
              },
              {
                "status": "executed",
                "id": "9b43d8e3e64e4b109196b84647fa54dcbf9f206e8e0deeb8f66bd661223b41a5"
              }
            ]
          }
        ]
      ]
    }
  ],
  "input_transactions": [
    {
      "signatures": [
        "EOSJvKdMyTMS8NgTSycDcrVT1stA4TS7xw4GeRWa9W7butiPKFBAwhZpvHQhAMMSkd4nQro9s4CevJXDURQeGq4F7es5HNPXP"
      ],
      "compression": "none",
      "hex_data": "6baf9e5a0000ac008b726be60000000000010000001e4d75af460000000000a53176010000001e4d75af4600000000a8ed3232180000001e4d75af4600841316dd5100000443555200000000",
      "data": {
        "expiration": "2018-03-06T15:10:35",
        "region": 0,
        "ref_block_num": 172,
        "ref_block_prefix": 3865801355,
        "packed_bandwidth_words": 0,
        "context_free_cpu_bandwidth": 0,
        "context_free_actions": [],
        "actions": [
          {
            "account": "currency",
            "name": "issue",
            "authorization": [
              {
                "actor": "currency",
                "permission": "active"
              }
            ],
            "data": {
              "to": "currency",
              "quantity": "9001000000.0000 CUR"
            },
            "hex_data": "0000001e4d75af4600841316dd5100000443555200000000"
          }
        ]
      }
    },
    {
      "signatures": [
        "EOSKeRM5hH4iqauWUqaT2k7qqd86uErbNqPjKND6jKCnqdjrBrAkyWj1PrNf7vXXcChEuqfhgxSSRYCwTkLvPhq33FSRTRaww"
      ],
      "compression": "none",
      "hex_data": "6baf9e5a0000ac008b726be60000000000010000001e4d75af46000000572d3ccdcd010000001e4d75af4600000000a8ed3232210000001e4d75af46000000008093dd7400e40b5402000000044355520000000000",
      "data": {
        "expiration": "2018-03-06T15:10:35",
        "region": 0,
        "ref_block_num": 172,
        "ref_block_prefix": 3865801355,
        "packed_bandwidth_words": 0,
        "context_free_cpu_bandwidth": 0,
        "context_free_actions": [],
        "actions": [
          {
            "account": "currency",
            "name": "transfer",
            "authorization": [
              {
                "actor": "currency",
                "permission": "active"
              }
            ],
            "data": {
              "from": "currency",
              "to": "initb",
              "quantity": "1000000.0000 CUR",
              "memo": ""
            },
            "hex_data": "0000001e4d75af46000000008093dd7400e40b5402000000044355520000000000"
          }
        ]
      }
    },
    {
      "signatures": [
        "EOSKdPZwo1uyVJ3HvS3wyN3BZc13QvYXHcidsBKWo89Ha1qfX5F96z6kzBT2tGyenyngUbo5bvKsLHG9AHB4uUFc8LQqqqT9M"
      ],
      "compression": "none",
      "hex_data": "6baf9e5a0000ac008b726be60000000000010000001e4d75af46000000572d3ccdcd01000000008093dd7400000000a8ed323221000000008093dd740000008a4dd3505700e40b5402000000044355520000000000",
      "data": {
        "expiration": "2018-03-06T15:10:35",
        "region": 0,
        "ref_block_num": 172,
        "ref_block_prefix": 3865801355,
        "packed_bandwidth_words": 0,
        "context_free_cpu_bandwidth": 0,
        "context_free_actions": [],
        "actions": [
          {
            "account": "currency",
            "name": "transfer",
            "authorization": [
              {
                "actor": "initb",
                "permission": "active"
              }
            ],
            "data": {
              "from": "initb",
              "to": "exchange",
              "quantity": "1000000.0000 CUR",
              "memo": ""
            },
            "hex_data": "000000008093dd740000008a4dd3505700e40b5402000000044355520000000000"
          }
        ]
      }
    }
  ],
  "id": "000000ada96204d352fefe15e300dee94d98c1514616fdee6c6e7e6ad6083ba3",
  "block_num": 173,
  "ref_block_prefix": 369032786
}

Any way to get multiple blocks with one getblock call? I want to list several blocks but don’t want a call for each block

You can enable an index and get all actions of a certain type. (see getActions and --filter-on)

Any way to get multiple blocks with one getblock call? I want to list several blocks but don’t want a call for each block

Any update on this @ameshkin @jordigoyanes . Have you figured out any right way to get the list of blocks in a single call. I wasn't able to see it listed in the documentation.

The nodeos v1 API doesn't support getting a list of blocks. It likely never will because:

  1. The JSON form of the blocks wastes a lot of network bandwidth. Several public nodes reject frequent block requests.
  2. Most users who want to fetch multiple blocks are trying to either collect historical data or respond to events. This use case is fundamentally broken. e.g. the blocks are missing a very large number of token transfers since these are often inline actions. There are several community-created tools which use the State History Plugin to provide the missing data.

@tbfleming But, inorder to fetch recent blocks what is the process I have to follow? Can you please point me out to the right direction? I saw you mentioned StateHistory plugin, but I don't see any examples listed out there.

Right now community-created history tools that rely on the state-history plugin provide the best option. We don't support them and I don't keep a list of them.