Retrieve a data contract#
In this tutorial we will retrieve the data contract created in the Register a Data Contract tutorial.
Prerequisites#
General prerequisites (Node.js / Dash SDK installed)
A configured client: Setup SDK Client
A Dash Platform Contract ID: Tutorial: Register a Data Contract
Code#
contract-retrieve.mjs#
import { setupDashClient } from '../setupDashClient.mjs';
const { sdk } = await setupDashClient();
// Default tutorial contract (testnet). Replace or override via DATA_CONTRACT_ID.
const DATA_CONTRACT_ID =
process.env.DATA_CONTRACT_ID ||
'FW3DHrQiG24VqzPY4ARenMgjEPpBNuEQTZckV8hbVCG4';
try {
const contract = await sdk.contracts.fetch(DATA_CONTRACT_ID);
console.log('Contract retrieved:\n', contract.toJSON());
} catch (e) {
console.error('Something went wrong:\n', e.message);
}
Example Data Contract#
The following example response shows a retrieved contract:
{
"$format_version": "1",
"id": "FW3DHrQiG24VqzPY4ARenMgjEPpBNuEQTZckV8hbVCG4",
"config": {
"$format_version": "0",
"canBeDeleted": false,
"readonly": false,
"keepsHistory": false,
"documentsKeepHistoryContractDefault": false,
"documentsMutableContractDefault": true,
"documentsCanBeDeletedContractDefault": true,
"requiresIdentityEncryptionBoundedKey": null,
"requiresIdentityDecryptionBoundedKey": null
},
"version": 2,
"ownerId": "CtnBVhWjGhtPihUHKS132b9f9zSKMxRHDA6wSDtjRofy",
"schemaDefs": null,
"documentSchemas": {
"note": {
"type": "object",
"properties": ["Object"],
"additionalProperties": false
}
},
"createdAt": null,
"updatedAt": null,
"createdAtBlockHeight": null,
"updatedAtBlockHeight": null,
"createdAtEpoch": null,
"updatedAtEpoch": null,
"groups": {},
"tokens": {},
"keywords": [],
"description": null
}
Note
Please refer to the data contract reference page for more comprehensive details related to contracts and documents.
What’s Happening#
After we initialize the client, we call sdk.contracts.fetch() with a contract ID. After the contract is retrieved, it is displayed on the console.