-
Notifications
You must be signed in to change notification settings - Fork 56
feat(api): add pagination page for v3 api #1869
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
Open
laviniat1996
wants to merge
11
commits into
main
Choose a base branch
from
v3-pagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+247
−1
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e1a3d7e
add pagination info for v3 api
laviniat1996 985e60a
Merge branch 'main' into v3-pagination
laviniat1996 931836f
fix linting
laviniat1996 b0aa475
fix numeric columns
laviniat1996 7c16595
Merge branch 'main' into v3-pagination
laviniat1996 3933b74
Merge branch 'main' into v3-pagination
laviniat1996 2df9daa
Merge branch 'main' into v3-pagination
aigerimu cd1af05
Merge branch 'main' into v3-pagination
aigerimu 66deb71
editing
aigerimu 23cad35
Update ecosystem/api/toncenter/v3-pagination.mdx
aigerimu d51d9c2
ai
aigerimu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,245 @@ | ||
| --- | ||
| title: "Pagination" | ||
| --- | ||
|
|
||
| import { Aside } from '/snippets/aside.jsx'; | ||
|
|
||
| The v3 API uses offset-based pagination. Each paginated endpoint accepts `limit` and `offset` parameters. `limit` controls how many results to return per request, and `offset` skips a number of rows from the beginning of the result set. To retrieve the next page, increment `offset` by the value of `limit`. | ||
|
|
||
| The following endpoints support pagination: | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| | Endpoint | Default limit | Max limit | Sortable | | ||
| | --------------------------------------------------------------------------------------------------------------------- | :-----------: | :-------: | :------: | | ||
| | [`transactions`](/ecosystem/api/toncenter/v3/blockchain-data/get-transactions) | 10 | 1000 | Yes | | ||
| | [`actions`](/ecosystem/api/toncenter/v3/actions-and-traces/get-actions) | 10 | 1000 | Yes | | ||
| | [`blocks`](/ecosystem/api/toncenter/v3/blockchain-data/get-blocks) | 10 | 1000 | Yes | | ||
| | [`messages`](/ecosystem/api/toncenter/v3/blockchain-data/get-messages) | 10 | 1000 | Yes | | ||
| | [`traces`](/ecosystem/api/toncenter/v3/actions-and-traces/get-traces) | 10 | 1000 | Yes | | ||
| | [`jetton/burns`](/ecosystem/api/toncenter/v3/jettons/get-jetton-burns) | 10 | 1000 | Yes | | ||
| | [`jetton/transfers`](/ecosystem/api/toncenter/v3/jettons/get-jetton-transfers) | 10 | 1000 | Yes | | ||
| | [`jetton/wallets`](/ecosystem/api/toncenter/v3/jettons/get-jetton-wallets) | 10 | 1000 | Yes | | ||
| | [`nft/items`](/ecosystem/api/toncenter/v3/nfts/get-nft-items) | 10 | 1000 | Yes | | ||
| | [`nft/transfers`](/ecosystem/api/toncenter/v3/nfts/get-nft-transfers) | 10 | 1000 | Yes | | ||
| | [`multisig/orders`](/ecosystem/api/toncenter/v3/multisig/get-multisig-orders) | 10 | 1000 | Yes | | ||
| | [`multisig/wallets`](/ecosystem/api/toncenter/v3/multisig/get-multisig-wallets) | 10 | 1000 | Yes | | ||
| | [`transactionsByMasterchainBlock`](/ecosystem/api/toncenter/v3/blockchain-data/get-transactions-by-masterchain-block) | 10 | 1000 | Yes | | ||
| | [`jetton/masters`](/ecosystem/api/toncenter/v3/jettons/get-jetton-masters) | 10 | 1000 | No | | ||
| | [`nft/collections`](/ecosystem/api/toncenter/v3/nfts/get-nft-collections) | 10 | 1000 | No | | ||
| | [`dns/records`](/ecosystem/api/toncenter/v3/dns/get-dns-records) | 100 | 1000 | No | | ||
| | [`masterchainBlockShards`](/ecosystem/api/toncenter/v3/blockchain-data/get-masterchain-block-shard-state-1) | 10 | 1000 | No | | ||
| | [`topAccountsByBalance`](/ecosystem/api/toncenter/v3/stats/get-top-accounts-by-balance) | 10 | 1024 | No | | ||
| | [`transactionsByMessage`](/ecosystem/api/toncenter/v3/blockchain-data/get-transactions-by-message) | 10 | 1000 | No | | ||
| | [`vesting`](/ecosystem/api/toncenter/v3/vesting/get-vesting-contracts) | 10 | 1000 | No | | ||
|
|
||
| All other v3 endpoints return single objects or fixed results and do not support pagination. | ||
|
|
||
| ## Parameters | ||
|
|
||
| These parameters are shared across all paginated endpoints. | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --------- | ------- | --------------------------------------------------------------------------------------------------------- | | ||
| | `limit` | integer | Maximum number of rows to return. Defaults vary by endpoint; see table above. | | ||
| | `offset` | integer | Number of rows to skip from the beginning of the result set. Default is `0`. | | ||
| | `sort` | string | Sort order: `desc` (default, newest first) or `asc` (oldest first). Available only on sortable endpoints. | | ||
|
|
||
| ## Pagination example | ||
|
|
||
| This example uses the `transactions` endpoint, but the same `limit` and `offset` pattern applies to all paginated endpoints. | ||
|
|
||
| <Steps> | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Step | ||
| title="Fetch the first page" | ||
| > | ||
| Send a request with `account` and `limit`. `offset` defaults to `0` for the first page. | ||
|
|
||
| ```bash | ||
| curl "https://toncenter.com/api/v3/transactions?account=EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2&limit=3" | ||
| ``` | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Response (abbreviated): | ||
|
|
||
| ```json | ||
| { | ||
| "transactions": [ | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "KkpVTX9RwiZcug8KQuOFUF8+eNoxuHVuIFpGQqufCWU=", | ||
| "lt": "67064337000004", | ||
| "now": 1771410670 | ||
| }, | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "b5fhFby+j8gg936W+XEsAEhboQW0zPcOHOHgyqXkTwI=", | ||
| "lt": "67011337000003", | ||
| "now": 1771286044 | ||
| }, | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "lT/wWTiJIdEF8A2Rox9CRdQRzlUgnIDGeUfEHQ8jGZQ=", | ||
| "lt": "66986300000006", | ||
| "now": 1771226782 | ||
| } | ||
| ], | ||
| "address_book": { ... } | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| Three transactions returned, sorted by logical time in descending order (newest first). | ||
| </Step> | ||
|
|
||
| <Step | ||
| title="Fetch the next page" | ||
| > | ||
| Set `offset=3` to skip the first 3 results and get the next batch. | ||
|
|
||
| ```bash | ||
| curl "https://toncenter.com/api/v3/transactions?account=EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2&limit=3&offset=3" | ||
| ``` | ||
|
|
||
| Response (abbreviated): | ||
|
|
||
| ```json | ||
| { | ||
| "transactions": [ | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "07QaeBRRA62+RJPgetgSraYLH5i9G5QhC2dUvKAsAiI=", | ||
| "lt": "66927779000007", | ||
| "now": 1771088713 | ||
| }, | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "8d7sSor1NqbGNdX1JEGl1d4rX3lb7CeC3DZjhe7V7z4=", | ||
| "lt": "66927779000003", | ||
| "now": 1771088713 | ||
| }, | ||
| { | ||
| "account": "0:ED1691307050047117B998B561D8DE82D31FBF84910CED6EB5FC92E7485EF8A7", | ||
| "hash": "szM1I5/MU1uJGgeScS7uxNF6V/FsLkokCpul88ZEau8=", | ||
| "lt": "66926353000007", | ||
| "now": 1771085323 | ||
| } | ||
| ], | ||
| "address_book": { ... } | ||
| } | ||
| ``` | ||
|
|
||
| No overlap with the previous page. Offset pagination does not produce duplicates. | ||
| </Step> | ||
|
|
||
| <Step | ||
| title="Repeat until the last page" | ||
| > | ||
| Continue incrementing `offset` by the `limit` value on each request (`offset=6`, `offset=9`, ...). When the response returns fewer transactions than the `limit`, all results have been retrieved. | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Accordion | ||
| title="Full pagination script" | ||
| > | ||
| ```javascript | ||
| const address = "EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2"; | ||
|
|
||
| async function main() { | ||
| let allTransactions = []; | ||
| let offset = 0; | ||
| const limit = 3; | ||
| let page = 0; | ||
|
|
||
| while (true) { | ||
| page++; | ||
| const params = new URLSearchParams({ | ||
| account: address, | ||
| limit: String(limit), | ||
| offset: String(offset), | ||
| }); | ||
|
|
||
| const res = await fetch( | ||
| `https://toncenter.com/api/v3/transactions?${params}` | ||
| ); | ||
| const data = await res.json(); | ||
| const transactions = data.transactions || []; | ||
|
|
||
| console.log(`\n--- Page ${page} (offset=${offset}) ---`); | ||
|
|
||
| for (const tx of transactions) { | ||
| console.log(` lt: ${tx.lt} hash: ${tx.hash}`); | ||
| } | ||
|
|
||
| allTransactions.push(...transactions); | ||
|
|
||
| if (transactions.length < limit) break; | ||
|
|
||
| offset += limit; | ||
| } | ||
|
|
||
| console.log(`\nTotal transactions: ${allTransactions.length}`); | ||
| } | ||
|
|
||
| main(); | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| Output: | ||
|
|
||
| ```bash | ||
| --- Page 1 (offset=0) --- | ||
| lt: 67064337000004 hash: KkpVTX9RwiZcug8KQuOFUF8+eNoxuHVuIFpGQqufCWU= | ||
| lt: 67011337000003 hash: b5fhFby+j8gg936W+XEsAEhboQW0zPcOHOHgyqXkTwI= | ||
| lt: 66986300000006 hash: lT/wWTiJIdEF8A2Rox9CRdQRzlUgnIDGeUfEHQ8jGZQ= | ||
|
|
||
| --- Page 2 (offset=3) --- | ||
| lt: 66927779000007 hash: 07QaeBRRA62+RJPgetgSraYLH5i9G5QhC2dUvKAsAiI= | ||
| lt: 66927779000003 hash: 8d7sSor1NqbGNdX1JEGl1d4rX3lb7CeC3DZjhe7V7z4= | ||
| lt: 66926353000007 hash: szM1I5/MU1uJGgeScS7uxNF6V/FsLkokCpul88ZEau8= | ||
|
|
||
| --- Page 3 (offset=6) --- | ||
|
|
||
| Total transactions: 6 | ||
| ``` | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </Accordion> | ||
|
|
||
| ## Sorting options | ||
|
|
||
| Sortable endpoints accept a `sort` parameter with two values: | ||
|
|
||
| - `desc` (default): newest results first, sorted by logical time (or UTC timestamp for `blocks`). | ||
| - `asc`: oldest results first. | ||
|
|
||
| ```bash | ||
| curl "https://toncenter.com/api/v3/transactions?account=EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2&limit=3&sort=asc" | ||
| ``` | ||
|
|
||
| Response (abbreviated): | ||
|
|
||
| ```json | ||
| { | ||
| "transactions": [ | ||
| { | ||
| "hash": "3ziyP0yvGklMTNWWXDplmlBcPH0P7MJtusoVthNu8e0=", | ||
| "lt": "39547833000003", | ||
| "now": 1690204554 | ||
| }, | ||
| { | ||
| "hash": "lYXDtLL53JkKa35vP05gbwTyd6Lq4335TwlZeUebxZ8=", | ||
| "lt": "39547876000003", | ||
| "now": 1690204686 | ||
| }, | ||
| { | ||
| "hash": "DSz0P/wmE0EkdfaxFl2R36Eie+Lw4paLa1sAHHUliJA=", | ||
| "lt": "39548648000003", | ||
| "now": 1690207175 | ||
| } | ||
| ], | ||
| "address_book": { ... } | ||
| } | ||
| ``` | ||
|
|
||
| With `sort=asc`, the earliest transactions are returned first, starting from 2023-07 for this account. | ||
|
|
||
| <Aside | ||
| type="caution" | ||
| title="Sorting with jetton/wallets" | ||
| > | ||
| The `jetton/wallets` endpoint sorts results by balance instead of logical time. When balances change between requests, using `limit` and `offset` can skip or repeat wallets because the sort order changes between pages. | ||
| </Aside> | ||
aigerimu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.