const Dash = require('dash') | |
const clientOpts = { | |
network: 'testnet', | |
mnemonic: 'a Dash wallet mnemonic with evonet funds goes here' | |
} | |
const client = new Dash.Client(clientOpts) | |
const registerContract = async function() { | |
try { | |
await client.isReady() | |
const platform = client.platform | |
const identity = await platform.identities.get('an identity ID goes here') | |
const contractDocumentWithDefinitions = { | |
documents: { | |
note: { | |
// Currently unclear how to set indices for nested object properties: | |
// indices: [ | |
// { | |
// properties: [ | |
// { | |
// 'message.timestamp': 'asc' | |
// } | |
// ], | |
// unique: false | |
// } | |
// ], | |
properties: { | |
// You cannot use definitions at toplevel current, only nested in objects | |
// See: https://github.com/dashevo/js-dpp/issues/185 | |
message: { | |
$ref: '#/definitions/msg' | |
} | |
}, | |
additionalProperties: false | |
} | |
}, | |
definitions: { | |
msg: { | |
// You cannot use indices here, only at toplevel | |
// You can set required properties here | |
required: ['timestamp'], | |
properties: { | |
timestamp: { | |
type: 'number' | |
}, | |
description: { | |
type: 'string' | |
} | |
}, | |
additionalProperties: false | |
} | |
} | |
} | |
const { documents, definitions } = contractDocumentWithDefinitions | |
const contract = await platform.contracts.create(documents, identity) | |
console.dir({ contract }) | |
// Set contract definitions | |
contract.setDefinitions(definitions) | |
console.dir({ contract }) | |
// Make sure contract passes validation checks | |
await platform.dpp.dataContract.validate(contract) | |
// Sign and submit the data contract | |
await platform.contracts.broadcast(contract, identity) | |
} catch (e) { | |
console.error('Something went wrong:', e) | |
} finally { | |
client.disconnect() | |
} | |
} | |
registerContract() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment