Write data
Publish a string or a structured value as a data output, decide whether it is signed and encrypted, and read it back.
A data output publishes a value. It is the output type most integrations reach for first, because it carries whatever your system already has: an identifier, a status change, a small structured record.
What a data output takes
Four fields, one of them required. The shape as @mintblue/sdk 9.6.0 declares
it, verbatim:
export interface DataOutput {
type: 'data';
/** Data to publish */
value: any;
/** Set to true to add digital signature */
sign?: boolean;
/** Set to true to encrypt value */
encrypt?: boolean;
}value is typed as any, so a string and a structured object are both
accepted. Pick one shape per project and keep to it: whatever you submit is what
you have to parse on the way back out, and a record that is a string in some
transactions and an object in others makes every reader more complicated than it
needs to be.
A string, when the record is one fact:
const outputs = [
{
type: 'data',
value: 'invoice INV-0001 approved',
sign: true,
encrypt: true,
},
];An object, when the record has fields you will want to read separately:
const outputs = [
{
type: 'data',
value: {
order_id: 'order-123',
order_reference: 'PO-77120',
order_items: [{ item_id: 'item-1', item_price: 100 }],
},
sign: true,
encrypt: true,
},
];sign and encrypt both default to off, so a data output submitted without
them publishes the value in the clear and unsigned.
Encrypt and sign an output covers what
each flag changes and how to tell from the outside that it worked.
Submit it
const { txid } = await client.createTransaction({
project_id: process.env.MINTBLUE_PROJECT_ID,
outputs,
});Check it worked
Fetch the transaction with parse: true and look at the data output. If the
value came back the way it went in, the round trip is complete.
const transaction = await client.getTransaction({ txid, parse: true });
const record = transaction.outputs.find((output) => output.type === 'data');
console.log(record.value);Where the bytes go
A data output is published in an OP_RETURN script, and the value travels
inside an envelope rather than as loose bytes. The envelope is what makes a
record readable by something other than the code that wrote it: it carries the
encrypted content, the signatures over it and the metadata that says how to read
the rest.
Two documents describe envelopes, and they describe different generations of the format.
- The format the shipped SDK writes today is documented here, one page per format, under Envelope formats.
- The envelope as the open SDX Protocol specifies it is at sdxprotocol.org/reference/envelope. That is the normative document for the protocol's own generation of the format, and this site does not restate it.
Generations sets out which of the two applies to the code you installed.