diff --git a/content/_code-samples/markers-and-pagination/js/pagination-with-markers.js b/content/_code-samples/markers-and-pagination/js/pagination-with-markers.js index 134f3ddf19..86cff23b2a 100644 --- a/content/_code-samples/markers-and-pagination/js/pagination-with-markers.js +++ b/content/_code-samples/markers-and-pagination/js/pagination-with-markers.js @@ -6,29 +6,30 @@ async function main() { const client = new xrpl.Client("wss://xrplcluster.com/") await client.connect() - // Specify a ledger to query for info. + // Query the most recently validated ledger for info. let ledger = await client.request({ "command": "ledger_data", - "ledger_index": 500000, + "ledger_index": "validated", }) + const ledger_data_index = ledger["result"]["ledger_index"] // Create a function to run on each API call. - function code(){ + function printLedgerResult(){ console.log(ledger["result"]) } // Execute function at least once before checking for markers. do { - code() + printLedgerResult() - if (ledger["result"]["marker"] == null) { + if (ledger["result"]["marker"] === undefined) { break } // Specify the same ledger and add the marker to continue querying. const ledger_marker = await client.request({ "command": "ledger_data", - "ledger_index": 500000, + "ledger_index": ledger_data_index, "marker": ledger["result"]["marker"] }) ledger = ledger_marker @@ -39,4 +40,4 @@ async function main() { client.disconnect() } -main() \ No newline at end of file +main() diff --git a/content/_code-samples/markers-and-pagination/py/pagination-with-markers.py b/content/_code-samples/markers-and-pagination/py/pagination-with-markers.py index a8e4e98f83..1972a2c246 100644 --- a/content/_code-samples/markers-and-pagination/py/pagination-with-markers.py +++ b/content/_code-samples/markers-and-pagination/py/pagination-with-markers.py @@ -4,20 +4,21 @@ from xrpl.models.requests import LedgerData # Create a client to connect to the network. client = JsonRpcClient("https://xrplcluster.com/") -# Specify a ledger to query for info. -ledger = LedgerData(ledger_index=500000) +# Query the most recently validated ledger for info. +ledger = LedgerData(ledger_index="validated") ledger_data = client.request(ledger).result +ledger_data_index = ledger_data["ledger_index"] # Create a function to run on each API call. -def code(): +def printLedgerResult(): print(ledger_data) # Execute function at least once before checking for markers. while True: - code() + printLedgerResult() if "marker" not in ledger_data: break # Specify the same ledger and add the marker to continue querying. - ledger_marker = LedgerData(ledger_index=500000, marker=ledger_data["marker"]) - ledger_data = client.request(ledger_marker).result \ No newline at end of file + ledger_marker = LedgerData(ledger_index=ledger_data_index, marker=ledger_data["marker"]) + ledger_data = client.request(ledger_marker).result