Skip to main content

Getting Started

Overview

This tutorial will guide you on how to send a transaction to the Bitcoin blockchain using the mintBlue SDK. You will set up a new project directory, install the SDK, and store a customer invoice ID on the Bitcoin blockchain using a data output.

Prerequisites

Step 1: Set up your project

Make sure you have a project set up with the below skeleton code.

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

async function main() {
const sdkToken = '<YOUR-SDK-TOKEN>';
const project_id = '<YOUR-PROJECT-ID>';

const client = await Mintblue.create({ token: sdkToken });

// Add the rest of the code here
}

main();

Step 2: Prepare the outputs

Imagine we are dealing with a customer invoice. We want to store the invoice ID and customer information on the Bitcoin blockchain.

As we want to store data, let's use the Data Output. A data output allows you to store any textual information. The type indicates the output type, which is set to data. The value key is used to store your data. It contains the customer's name, customer email, and order ID.

const outputs = [
{
type: "data",
value: {
name: "John Doe",
email: "john@doe.com",
order: "order#1234",
}
}
];

Ok, we are ready to submit the transaction to mintBlue. The mintBlue platform will take care of final storage on the Bitcoin blockchain.

Step 3: Submit the transaction

Finally, let's submit the transaction with our outputs to the mintBlue platform. We can use the createTransaction function on the mintBlue client that accepts an object containing our project_id and outputs.

const { txid, rawtx } = await client.createTransaction({
project_id,
outputs,
});

Let's log the transaction ID (txid) to your terminal so we can look up the transaction using a blockchain explorer. For demo purposes, we are using https://whatsonchain.com to look up the transaction.

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

Step 4: Execute the code ✅

Your final code will look like this.

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

async function main() {
const sdkToken = '<YOUR-SDK-TOKEN>';
const project_id = '<YOUR-PROJECT-ID>';

const client = await Mintblue.create({ token: sdkToken });

const outputs = [
{
type: "data",
value: {
name: "John Doe",
email: "john@doe.com",
order: "order#1234",
}
},
];

const { txid, rawtx } = await client.createTransaction({
project_id,
outputs,
});

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

main();

To execute our code, you can use the node command. Make sure you've replaced the <YOUR-SDK-TOKEN> and <YOUR-PROJECT-ID> variables.

node main.js
info

It's recommended to use TypeScript to benefit from type checking. Make sure to first compile your code before executing it.

Summary

In this tutorial for SDK Transactions, you've learned the following steps:

  • ✅ Instantiate a mintBlue client object.
  • ✅ Prepare a data output.
  • ✅ Submit a transaction to mintBlue, which will take care of storage on the Bitcoin blockchain.

What should I learn next?

Make sure to read about the different Output Types.

Next, you can explore the output type how-to guides like Payment Output, File Output, and how to Combine Outputs. It's also valuable to check out how to Encrypt and Sign Outputs to protect sensitive information because data stored on a blockchain is accessible to anyone.