How to get block number in casper

What is block.number of solidity in casper chain(RUST)?

Hey Antko,

Thanks for your question. I will get an example compiled for you and follow up. To clarify, you’re looking to obtain the latest block from the chain on the casper network, correct?

Thanks,

Kavma

@antko you know when you’ve had a long day and your brain doesn’t quite work? that’d be me today!

The casper-client uses rust and can obtain the current block with the following command:

casper-client get-block --node-address http://localhost:7777

You can see the source code for casper-client get-block on our github page.

@Kavma , How can you get the highest block on the network ? I would like to see the sync status of my node

this is available on port 8888/status on the node.

@arrajput there’s a few ways you can get the latest block on the network. If you want to check your own node’s block height, you can submit a curl like this:

curl -s localhost:8888/status | jq .last_added_block_info

You’ll want to compare that to the block explorer, cspr.live for mainnet, or testnet.cspr.live for the testnet. You will be able to see the latest block on the front page.

If you want to curl another node on the network, click “tools” and then “connected peers”, you can then use the same command above with the new node’s IP to get their last added block instead.

If you’d like to accomplish this by the casper-client:

casper-client get-block --node-address http://<node_address_here>:7777

and additionally you can curl the RPC port of a node on the network for this information:

curl --location --request POST ‘http://<NODE_IP>:7777/rpc’ --header ‘Content-Type: application/json’ --data-raw ‘{
“jsonrpc”: “2.0”,
“id”: 2,
“method”: “chain_get_block”,
“params”: { }
}’ | jq

I hope this helps!