Last active
November 23, 2022 11:51
-
-
Save saitgulmez/eca7a3072512f0a9c9ee7453ba582457 to your computer and use it in GitHub Desktop.
Get block and block members at a provided block hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'casper_network' | |
| # Following IP addres is taken from https://testnet.cspr.live/tools/peers | |
| YOUR_CASPER_NETWORK_NODE_IP_ADDRESS = "65.108.73.113" | |
| # We'll use this to connect to the Casper Network. | |
| client = Casper::CasperClient.new(YOUR_CASPER_NETWORK_NODE_IP_ADDRESS) | |
| block_hash = "53943d39b0ea69dbdd3e255cfafbe0a3d610ccd0e83d86c83ee6d2f623b92e84" | |
| block = client.chain_get_block(block_hash) | |
| # A Block object | |
| puts block | |
| # To retrieve Block hash | |
| block_hash = block.get_hash | |
| puts block_hash | |
| # 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 all proofs members and print each of these members and their attributes value | |
| 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