Skip to main content

Payment Output

Summary

This how-to guide explains how to create a payment transaction  to send BSV to another address on the Bitcoin blockchain using the mintBlue SDK.

Prerequisites

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

Video Guide

In this video, we show you how to create a transaction with a payment output using the mintBlue SDK.

Prepare payment outputs

First, we need to prepare payment outputs. Here is its interface.

interface PaymentOutput {
  type: 'payment';
  // Recipient's Paymail address or BSV address
  to: string;
  satoshis: number;
}

You can choose to send a payment to a BSV address or to a Paymail address. 1000 satoshis equal 0.00001 BSV.

const outputs = [
  {
      type: 'payment',
      // to: 'name@paymail.com' // Paymail address
      to: '1FoXXU8xneLzkS1Hrhg8Hck7MJLvy3Uzyx', // BSV address
      satoshis: 1000,
  }
];

Send the transaction to mintBlue

Next, let's send the payment to mintBlue. 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 payment 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. Here's what your transaction output should look like. The first object in the array is your payment output.

[
  {
    "type": "payment",
    "to": "1FoXXU8xneLzkS1Hrhg8Hck7MJLvy3Uzyx",
    "satoshis": 1000
  },
  {
    "type": "payment",
    "to": "1Juc9Tjmb6wc6yCaWFuB9QdEEQ621992ks",
    "satoshis": 23848
  }
]

Code Check  ✅

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

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

  const outputs = [
    {
        type: 'payment',
        //to: 'name@paymail.com',
        to: '1FoXXU8xneLzkS1Hrhg8Hck7MJLvy3Uzyx',
        satoshis: 1000,
  	}
  ];

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

main();