Skip to main content

Combine Outputs

Summary​

This how-to guide explains how you can combine multiple outputs and create a transaction on the Bitcoin blockchain using the mintBlue SDK. Let's explore storing data like an invoice ID and an invoice file.

Prerequisites​

We recommend you complete the Getting Started section to learn how to interact with mintBlue through the mintBlue SDK.

Prepare different outputs​

First, let's prepare multiple outputs: File Output and Data Output. You can add each output to the outputs array. It's possible to add multiple outputs of the same type. For example, adding two data outputs.

const outputs = [
{
type: "file",
value: {
contentType: "text/plain",
content: Buffer.from("Order #1234 [...]"),
},
sign: false,
encrypt: false,
},
{
type: "data",
value: {
name: "John Doe",
email: "john@doe.com",
order: "order#1234",
},
sign: true,
encrypt: true,
},
];

In short, you can add as many outputs as you need.

Send the transaction to mintBlue​

Next, let's send the customer order and invoice to mintBlue to handle the final Bitcoin blockchain storage. Here's how you can do this using the mintBlue SDK. Make sure to replace the <YOUR-PROJECT-ID>with your project ID.

const { txid, rawtx } = await client.createTransaction({
project_id: "<YOUR-PROJECT-ID>",
outputs,
});

Once the transaction has been created, the createTransaction function returns a transaction ID and the raw transaction data. To look up the transaction on a blockchain explorer, let's print the txid variable.

console.log(`https://whatsonchain.com/tx/${txid}`);

Look up the transaction output​

Let's look up the transaction output via the mintBlue console. Make sure to access the correct project.

[
{
"type": "file",
"encrypt": false,
"sign": false,
"value": {
"content": {
"type": "Buffer",
"data": [
79,
114,
100,
101,
114,
32,
35,
49,
50,
51,
52,
32,
91,
46,
46,
46,
93
]
},
"contentType": "text/plain"
}
},
{
"type": "data",
"encrypt": true,
"sign": true,
"value": {
"name": "John Doe",
"email": "john@doe.com",
"order": "order#1234"
}
},
{
"type": "payment",
"to": "1Juc9Tjmb6wc6yCaWFuB9QdEEQ621992ks",
"satoshis": 24850
}
]

Code Check  ✅​

const { Mintblue } = require("@mintblue/sdk");

async function main() {
const token = "<YOUR-SDK-TOKEN>";
const client = await Mintblue.create({ token });

const outputs = [
{
type: "file",
value: {
contentType: "text/plain",
content: Buffer.from("Order #1234 [...]"),
},
sign: false,
encrypt: false,
},
{
type: "data",
value: {
name: "John Doe",
email: "john@doe.com",
order: "order#1234",
},
},
];

const { txid, rawtx } = await client.createTransaction({
project_id: "<YOUR-PROJECT-ID>",
outputs,
});
console.log(`https://whatsonchain.com/tx/${txid}`);
}

main();