Guides
Dash CoreDash PlatformDash.orgDash User DocsLog In
Guides
These docs are for v0.16.0. Click to read the latest docs for v0.25-redirect.

Retrieve a Data Contract

Retrieve details for a Dash Platform Data Contract

Overview

In this tutorial we will retrieve the data contract created in the Register a Data Contract tutorial.

Prerequisites

Code

Retrieving a data contract

const Dash = require('dash');

const client = new Dash.Client();

const retrieveContract = async () => {
  const contractId = 'Q894cs83D8REQNo7mAetj1wPJK2W3svrwqaN61aP25W';
  return client.platform.contracts.get(contractId);
};

retrieveContract()
  .then((d) => console.dir(d.toJSON(), { depth: 5 }))
  .catch((e) => console.error('Something went wrong:\n', e))
  .finally(() => client.disconnect());

Example Data Contract

The following example response shows a retrieved contract:

{
  "protocolVersion": 0,
  "$id": "E18yBYfRLa4HiKgYevL6EEhVZ4HssBgGoiV8pwb1EaQb",
  "$schema": "https://schema.dash.org/dpp-0-4-0/meta/data-contract",
  "ownerId": "bKad7BSN23Yr4s6DHUQnNgUTGK4RMPx1LYuqoxRvMcv",
  "documents": {
    "note": {
      "properties": {
        "message": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}

๐Ÿ“˜

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 request a contract. The platform.contracts.get method takes a single argument: a contract ID. After the contract is retrieved, it is displayed on the console.