Skip to content

Get Blockchain info

wirfeon edited this page Feb 17, 2021 · 1 revision

Get the current height of the chain

from xpxchain import models
from xpxchain import client

ENDPOINT = '//localhost:3000'

with client.BlockchainHTTP(ENDPOINT) as http:
    height = http.get_blockchain_height()
    print(height)

Get BlockInfo for a given block height

  • Following parameters required:
    • Height - height of block to get info from
from xpxchain import models
from xpxchain import client

ENDPOINT = '//localhost:3000'
height = 100

with client.BlockchainHTTP(ENDPOINT) as http:
    block = http.get_block_by_height(height)
    print(block)

Get an array of BlockInfo for a given block height and limit

  • Following parameters required:
    • Height - height of block to get info from
    • Limit - how many block infos to return
from xpxchain import models
from xpxchain import client

ENDPOINT = '//localhost:3000'
height = 100
limit = 10

with client.BlockchainHTTP(ENDPOINT) as http:
    blocks = http.get_blocks_by_height_with_limit(height, limit)
    print(blocks)

Get transactions from a block

  • Following parameters required:
    • Height - height of block to get transactions from
from xpxchain import models
from xpxchain import client

ENDPOINT = '//localhost:3000'
height = 1

with client.BlockchainHTTP(ENDPOINT) as http:
    block = http.get_block_transactions(height)
    print(block)

Get the current score of the chain

from xpxchain import models
from xpxchain import client

ENDPOINT = '//localhost:3000'

with client.BlockchainHTTP(ENDPOINT) as http:
    score = http.get_blockchain_score()
    print(score)
Clone this wiki locally