Skip to content

Instantly share code, notes, and snippets.

@dashameter
Created June 3, 2020 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dashameter/9afc48276b3669de8875f0200eec6e5c to your computer and use it in GitHub Desktop.
Save dashameter/9afc48276b3669de8875f0200eec6e5c to your computer and use it in GitHub Desktop.
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