Skip to content

Instantly share code, notes, and snippets.

@saitgulmez
Last active November 22, 2022 18:31
Show Gist options
  • Select an option

  • Save saitgulmez/4fa3f706c85a6de5a435cc7d32f26116 to your computer and use it in GitHub Desktop.

Select an option

Save saitgulmez/4fa3f706c85a6de5a435cc7d32f26116 to your computer and use it in GitHub Desktop.
Get block info at a provided block height
require 'casper_network'
# Following IP addres is taken https://testnet.cspr.live/tools/peers
node_ip_address = "65.21.235.219"
client = Casper::CasperClient.new(node_ip_address)
block = client.get_block_by_height(1271722)
# A Block object
puts block
# To retrieve BlockHeader object
block_header = block.get_header
puts block_header
# To access and print members of the block_header object (block_header is an instance of BlockHeader )
puts block_header.get_parent_hash
puts block_header.get_state_root_hash
puts block_header.get_body_hash
puts block_header.get_random_bit
puts block_header.get_accumulated_seed
puts block_header.get_era_end
puts block_header.get_timestamp
puts block_header.get_era_id
puts block_header.get_height
puts block_header.get_protocol_version
# To retrieve BlockBody object
block_body = block.get_body
# To access and print members of the block_body object (block_body is an instance of BlockBody )
puts block_body
puts block_body.get_proposer
puts block_body.get_deploy_hashes
puts block_body.get_transfer_hashes
# To retrieve an array of BlockProof objects
proofs = block.get_proofs
# To access and print members of the block_proof objects (block_proof is an instance of BlockProof )
puts proofs
# To access and print each proof object and its members
i = 0
proofs.each do |proof|
puts "proofs[#{i}]: #{proof}"
puts "public_key: " + proof.get_public_key
puts "signature: " + proof.get_signature
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment