```{eval-rst} .. tutorials-retrieve-data-contract-history: ``` # Retrieve data contract history In this tutorial we will retrieve the history of a data contract created in the [Register a Data Contract tutorial](../../tutorials/contracts-and-documents/register-a-data-contract.md). Only contracts that have enabled the `keepsHistory` option during contract creation will store revision information. :::{note} This retrieves revisions of the contract definition. It does not return the revision history of individual documents (see [`getDocumentHistory`](../../reference/dapi-endpoints-platform-endpoints.md#getdocumenthistory)) or records of document transfers and sales (see [document ownership and pricing history](../../reference/glossary.md#history-document-ownership-and-pricing)). ::: ## Prerequisites * [General prerequisites](../../tutorials/introduction.md#prerequisites) (Node.js / Dash SDK installed) * A configured client: [Setup SDK Client](../setup-sdk-client.md) * A Dash Platform contract ID for a contract configured to keep history: [Tutorial: Register a Data Contract](../../tutorials/contracts-and-documents/register-a-data-contract.md) ## Code ```{code-block} javascript :caption: contract-retrieve-history.mjs import { setupDashClient } from '../setupDashClient.mjs'; const { sdk } = await setupDashClient(); // Default tutorial contract with history (testnet). Replace or override via DATA_CONTRACT_ID. const DATA_CONTRACT_ID = process.env.DATA_CONTRACT_ID || '5J4VPym1Bnc2Ap9bbo9wNw6fZLGsCzDM7ZScdzcggN1r'; try { const history = await sdk.contracts.getHistory({ dataContractId: DATA_CONTRACT_ID, }); for (const [timestamp, contract] of history) { console.log(`Version at ${timestamp}:`, contract.toJSON()); } } catch (e) { console.error('Something went wrong:\n', e.message); } ``` ```{raw} html