Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/larry0x/cosmos-sdk-historical-query
How to query a Cosmos chain at historical block heights in Rust, Go, JS, and Bash
https://github.com/larry0x/cosmos-sdk-historical-query
Last synced: 4 days ago
JSON representation
How to query a Cosmos chain at historical block heights in Rust, Go, JS, and Bash
- Host: GitHub
- URL: https://github.com/larry0x/cosmos-sdk-historical-query
- Owner: larry0x
- Created: 2023-12-16T23:57:38.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2023-12-17T02:32:30.000Z (11 months ago)
- Last Synced: 2024-08-01T13:30:28.255Z (3 months ago)
- Language: Go
- Homepage:
- Size: 80.1 KB
- Stars: 20
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ccamel - larry0x/cosmos-sdk-historical-query - How to query a Cosmos chain at historical block heights in Rust, Go, JS, and Bash (Go)
README
# cosmos-sdk-historical-query
Sample code for querying a Cosmos chain at a historical block height, in four languages:
- Rust
- Go
- JavaScript
- BashIn addition, the example persented here is a paginated query, meaning it may take more than one query to retrieve the full result. We show how to do this using a loop.
## How to use
Rust:
```bash
cd rust
cargo run
```Go:
```bash
cd go
go run main.go
```JavaScript:
```bash
cd js
node main.js
```Bash:
```bash
cd bash
bash main.sh
```Result should look like this:
```plain
performing query... next=""
performing query... next="14614fecb276f5e00c2fd0db40130023bb3f832175"
performing query... next="14ab2bc85eaa365c4cf39f6a7525b44fef8264512e"
performing query... next="14dbfdb0af1e9dc4a05a94074e6c900b29550b2dad"
[
{
"delegation": {
"delegator_address": "celestia15rpm3yhl76ps7s74nu5pg06atpz70slal4kdk2",
"validator_address": "celestiavaloper1qx43f066sh6728avms4qq09cj2a3mg83dgjh22",
"shares": "350000000000.000000000000000000"
},
"balance": {
"denom": "utia",
"amount": "350000000000"
}
},
{
"delegation": {
"delegator_address": "celestia15rpm3yhl76ps7s74nu5pg06atpz70slal4kdk2",
"validator_address": "celestiavaloper1qxeza0sa037u35p3ze8p7ka7emajvydnyjlp07",
"shares": "350000000000.000000000000000000"
},
"balance": {
"denom": "utia",
"amount": "350000000000"
}
},
...more
```If the node has already pruned the height you're querying at, an error like this should be returned:
```plain
codespace: sdk
code: 18
log: failed to load state at height 123; version mismatch on immutable IAVL tree; version does not exist. Version has either been pruned, or is for a future block height (latest height: 344122): invalid request
```