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

Retrieve a Data Contract

Overview

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

Code

Retrieving a data contract

const Dash = require('dash');

const clientOpts = {
  network: 'evonet',
};
const client = new Dash.Client(clientOpts);

const retrieveContract = async function () {
  try {
    const platform = client.platform;
    const contractId = '4xGhiiDR9o7VhpnW7YtLZvpWXdKByBgChZvUbri8ETJP';
    
    const contract = await platform.contracts.get(contractId);
    console.dir({contract});
  } catch (e) {
    console.error('Something went wrong:', e);
  } finally {
    client.disconnect();
  }
}

retrieveContract();

Example Data Contract

The following example response shows a retrieved contract:

{
  id: '4xGhiiDR9o7VhpnW7YtLZvpWXdKByBgChZvUbri8ETJP',
  ownerId: '58keGTkwoDycwWkRMmPYQMxVSEc6gy3fSTg59pfHAtdy',
  schema: 'https://schema.dash.org/dpp-0-4-0/meta/data-contract',
  documents: {
    note: {
      properties: {
        message: {
          type: 'string'
        }
      },
      additionalProperties: false
    }
  },
  definitions: undefined
}

๐Ÿ“˜

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.