Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get block hash from a block number #1897

Open
f-squirrel opened this issue Jan 18, 2025 · 1 comment
Open

How to get block hash from a block number #1897

f-squirrel opened this issue Jan 18, 2025 · 1 comment

Comments

@f-squirrel
Copy link
Contributor

f-squirrel commented Jan 18, 2025

I have noticed that subxt requires providing a block hash to download the block or block header.

How do I get a block hash if I only know its number?

In versions prior 0.34.0 there was the following API:

client.rpc().block_hash(block_id)

Where block_id is a number.

P.S. Unfortunately, I cannot subscribe to block updates. I use it as described here.

@f-squirrel
Copy link
Contributor Author

I found the following way to do it:

        let legacy_rpc_client = LegacyRpcMethods::<PolkadotConfig>::new(rpc_client.clone());
        legacy_rpc_client.chain_get_block_hash(block_number).await

I have to hold both LegacyRpcMethods and OnlineClient. It might be helpful to be able to get one from another since, anyway, both hold an Arc` to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant