Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ordinalsbot

ordinalsbot1.1kMIT0.2.16TypeScript support: included

Node.js library for OrdinalsBot API

bitcoin, lightning network, ordinals, api, ordinalsbot, inscriptions, buy, sell

readme

OrdinalsBot Node.js Library

Version Try ordinalsbot on RunKit

The OrdinalsBot Node library provides convenient access to the OrdinalsBot API from applications written in JavaScript.

Documentation

You can find examples here. For more information refer to our API docs.

Installation

Install the package with:

npm install ordinalsbot --save
or
yarn add ordinalsbot

Import and intialization

The package needs to be configured with your account's API key which you can get by opening a ticket in our Discord for now. Our developer dashboard is coming soon...

import { Ordinalsbot } from "ordinalsbot";

/**
 * Creates a new instance of Ordinalsbot with the provided API key, network type, optional TokenPay API key, and options.
 *
 * @param {string} API_KEY - The API key to authenticate requests.
 * @param {string} network - The network type to be used. Allowed values are 'testnet', 'mainnet', 'signet'. Defaults to 'mainnet'.
 * @param {string} [TOKENPAY_API_KEY] - Optional API key for TokenPay.
 * @param {ClientOptions} [options] - Optional configuration options for the client.
 * @returns {Ordinalsbot} An instance of the Ordinalsbot class.
 */
const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet", TOKENPAY_API_KEY);
const marketPlace = ordinalsbotObj.MarketPlace();
const inscription = ordinalsbotObj.Inscription();
const launchpad = ordinalsbotObj.Launchpad();
const mempool = ordinalsbotObj.Mempool();
const satextractor = ordinalsbotObj.Satextractor();
const satscanner = ordinalsbotObj.Satscanner();
// To use TokenPay, the `TOKENPAY_API_KEY` must be passed to the Ordinalsbot class
const tokenPay = ordinalsbotObj.TokenPay();

Usage

try {
  // create new order
  const order = await inscription.createOrder({
    files: [
      {
        size: 10,
        type: "plain/text",
        name: "my-text-inscription-file.txt",
        dataURL: "data:plain/text;base64,dGVzdCBvcmRlcg==",
      },
    ],
    lowPostage: true,
    receiveAddress: "",
    fee: 11,
  });
  console.log("Order: ", order);
} catch (error) {
  console.log("Exception: ", error);
}

try {
  // get marketplace listings
  const listing = await marketplace.getListing();
  console.log("Marketplaces: ", listing);
} catch (e) {
  console.log("Exception: ", e);
}

Using Promises

Every method returns a chainable promise which can be used instead of a regular callback:

// create new order
inscription
  .createOrder({
    files: [
      {
        size: 10,
        type: "plain/text",
        name: "my-text-inscription-file.txt",
        dataURL: "data:plain/text;base64,dGVzdCBvcmRlcg==",
      },
    ],
    lowPostage: true,
    receiveAddress: "",
    fee: 11,
  })
  .then((order) => {
    console.log("Order: ", order);
  })
  .catch((error) => {
    console.log("Exception: ", error);
  });

// get marketplace listings
marketplace
  .getListing()
  .then((listings) => {
    console.log("Order: ", listings);
  })
  .catch((error) => {
    console.log("Exception: ", error);
  });

Run examples

You can check and run examples after setting your API Key

npx ts-node examples/example.ts

Using Wallets on the client side

For client-side applications, the methods marketplace.createListing(), marketplace.createOffer(), and marketplace.setupPaddingOutputs() support the walletProvider parameter. This optional string parameter allows for specifying the wallet name, with current support for the Xverse wallet and plans to include additional wallets soon. When the walletProvider parameter is specified it triggers the invocation of the specified wallet, prompting the user to sign the transaction. This integration significantly streamlines the process by reducing the need for multiple API calls and simplifies the structuring of data required for wallet invocation and transaction signing.

The following example demonstrates how to create a listing for sale. When you invoke marketplace.createListing() and specify "xverse" as the walletProvider, it initiates an API call to generate a listing transaction. The method processes the response, formatting the data according to the requirements of the Xverse wallet. Subsequently, the Xverse wallet is activated to prompt the user to sign the transaction. Once the user successfully signs, this method additionally triggers the save-listing API, using the appropriately formatted data. Finally, it returns the confirmed listing information as the response.

import { Ordinalsbot } from "ordinalsbot";

/**
 * Creates a new instance of Ordinalsbot with the provided API key, network type, optional TokenPay API key, and options.
 *
 * @param {string} API_KEY - The API key to authenticate requests.
 * @param {string} network - The network type to be used. Allowed values are 'testnet', 'mainnet', 'signet'. Defaults to 'mainnet'.
 * @param {string} [TOKENPAY_API_KEY] - Optional API key for TokenPay.
 * @param {ClientOptions} [options] - Optional configuration options for the client.
 * @returns {Ordinalsbot} An instance of the Ordinalsbot class.
 */
const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet");
const marketPlace = ordinalsbotObj.MarketPlace();

const listingRequest = {
  sellerOrdinals: [{
    id: "0c9ac6fb5d4516aade728882e230b0d78337732ea71915c7fbc0cdabe5d29f3ci0",
    price: "1234"
  }],
  sellerPaymentAddress: "2NAurbuXjBK5dztb416bh98ibDS7MKxV75C",
  sellerOrdinalPublicKey: "594a4aaf5da5b144d0fa6b47987d966029d892fbc4aebb23214853e8b053702e",
  sellerOrdinalAddress: "tb1p79l2gnn7u8uqxfepd7ddeeajzrmuv9nkl20wpf77t2u473a2h89s483yk3",
  walletProvider: WALLET_PROVIDER.xverse
};

//call the marketplace listing method
const response = await marketPlace.createListing(listingRequest);

// this will invoke wallet and prompt the user to sign the transaction
// Once signed the listing data will be saved and the saved listing will be
// returned as the response

Using L402 for API Access

L402 is an alternative way to pay and authenticate access to an API, powered natively by Bitcoin and the Lightning Network. With L402, developers do not need an auth key to use an API. Instead, a micro lightning payment is requested for anonymous authentication. Once payment has been done, the preimage of the payment is used as proof-of-payment to grant access to API resources for a limited amount of calls.

OrdinalsBot has partnered with Sulu to offer developers all across the world access to their APIs through L402. All current OrdinalsBot endpoints can be paid for and accessed through L402 using the hostname https://ordinalsbot.ln.sulu.sh .

For a price of 5 sats for 5 calls developers can access any endpoint without rate limits or needing to obtain an auth key.

Furthermore, Sulu has integrated L402 functionality into the OrdinalsBot Node.js Library. With access to a Lightning Node or wallet, developers can seamlessly pay for usage of the OrdinalsBot API using Bitcoin:

import { AlbyWallet, MemoryTokenStore } from "l402";
const { Client } = require('@getalby/sdk');
import { ClientOptions, Satscanner } from "../src";
require('dotenv').config();

// Load the Alby token from an environment variable
const albyToken = process.env.ALBY_BEARER_TOKEN;
if (!albyToken) {
    console.error('Missing ALBY_BEARER_TOKEN environment variable.');
    process.exit(1);
}

const albyClient = new Client(albyToken)

// Initialize the AlbyWallet using the bearer token
const albyWallet = new AlbyWallet(albyClient);

// Initialize the MemoryTokenStore
const store = new MemoryTokenStore({
  keyMode: 'hostname-only' // this is IMPORTANT, since all endpoints are monetized 
                           // using the same hostname-level package ie. the same 
                           // L402 token can be used for all endpoints.
});

// Create Options to enable L402 access
const options: ClientOptions = {
    useL402: true,
    l402Config: {
        wallet: albyWallet,
        tokenStore: store
    }
};

// Create a new Satscanner instance
// Allowed environments are ('testnet', 'mainnet', 'signet')
// default environment is 'mainnet'.
const satscanner = new Satscanner("", "mainnet", options);

/**
 * use satscanner to get information about utxos owned by an address
 */
(async () => {
    try {
      const response = await satscanner.findSpecialRanges({ address: "bc1pjqmzr4ad437ltvfyn8pslcy8quls9ujfkrudpz6qxdh2j75qrncq44mp47" });
      console.log(response);
    } catch (error) {
      console.error(`${error.status} | ${error.message} | ${error.data}`);
    }
  })();

For more details on how the integration works, check out Sulu's l402 NPM package. At the time of writing, the Alby Wallet is the only officially supported wallet, but developers are free to write their own wallet integrations implementing the Wallet interface in the l402 package.

Testing

npm run test

changelog

[0.2.16]

  • Remove lowPostage param on order/price methods in favor of a postage accepting min value of 330 and max value of 10,000 sats

[0.2.15]

  • TokenPay
    • Updated tokenpay client so tokenpay api key is passed in header.
    • Added tokenpay sample code in examples

[0.2.14]

  • TokenPay

    • Moved options parameter to the 4th position in the Ordinalsbot constructor.
    • Added TOKENPAY_API_KEY as an optional 3rd parameter in the Ordinalsbot constructor to support TokenPay functionality.

    Example

    // Updated constructor usage
    const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet", TOKENPAY_API_KEY, options);
    
    // Usage with only the TOKENPAY_API_KEY
    const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet", TOKENPAY_API_KEY);
    
    // Usage with only the options parameter
    const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet", undefined, options);
    
    // Or without optional parameters
    const ordinalsbotObj = new Ordinalsbot(API_KEY, "testnet");

[0.2.13]

  • TokenPay
    • Added createRuneOrder - method to create rune order.
    • Added createPaymentPSBT - method for create payment psbt for an order.
    • Added checkTransactionAsTxid - method to checks the transaction status using the provided transaction ID (txid).
    • Added getOrder - method to retrieve the details of an order.
    • Added accountWithdraw - method to initiates an account withdrawal request.
    • Added getAccountWithdraw - method to retrieves the account withdrawal details.
    • Added getAccountBalance - method to retrieves the account balance.

[0.2.12]

  • Inscription
    • Updated createSpecialSatsPSBT - method request and response to create special sats psbt and xverse wallet support.

[0.2.11]

  • Inscription
    • Updated createDirectOrder - method to create multi parent parent child inscription order.
    • Added createParentChildPsbt - method for create parent child psbt for an order.

[0.2.10]

  • Fixed
    • Fixed the issue with the axios error when using sdk on frontend

[0.2.9]

  • Inscription
    • createCollection - Added phases in the request and response object.
    • updateCollectionPhases - Added method for updating the phases of a collection.
    • getAllocation - Added a method to check allowed and claimed inscription in collection phases for an address

[0.2.8]

  • Environment support added for all APIs except marketplace and launchpad
    • Environment can be tesnet, signet, mainnet
    • Default environment is mainnet
    • Backward compatibility maintained for live as mainnet environment and dev as testnet environment

[0.2.5]

  • Types

    • Added direct inscription types
  • Inscription

    • Added inscribe endpoint to enable support for direct inscriptions

[0.2.4]

  • Marketplace

    • deList - Added the confirmDelisting method after signTransaction.
    • confirmDeListing - Added confirmation method to delist the ordinal from the listing.

[0.2.3]

  • Types

    • Added delegates support to inscriptions and rune etching
    • Added metaprotocol to files or delegates array element
    • Added orderType: managed and rune-launchpad-mint
    • Added BatchModeType: for batchMode price and order requests
  • Inscription

    • Updated getPrice with type and batchMode

[0.2.2]

  • Types

    • Added OrderType enum
    • Added Runes Etching Types
    • Added 'sent' to InscriptionFile
  • Inscription

    • Added Rune Etching Order endpoint

[0.2.1]

  • Types

    • Added InscriptionOrderState enum
    • Updated InscriptionTextOrderRequest so the examples script runs
    • Added testing section in README

[0.2.0]

  • Types

    • type syncronization with OrdinalsBot API

[0.1.5]

APIs Added

  • Marketplace

    • getListing - Updated request and response object.
  • Launchpad

    • constructor - Added method constructor for initialization of launchpad instance
    • createMarketPlace - Added method for creating a launchpad marketplace
    • createLaunchpad - Added method for creating a launchpad listing
    • getLaunchpadPSBT - Added method for retrieving the launchpad PSBT to sign transaction
    • saveLaunchpad - Added method for updating the signed PSBT on the launchpad
    • getLaunchpadListing - Added method for retrieving the active launchpad listing
    • getAllocation - Added method for buyers to check allowed and claimed inscription for launchpad phases
    • confirmPaddingOutputs - Added method to check if the padding outputs are available in the buyer account
    • setupPaddingOutputs - Added method to set up if the padding outputs are not available in the buyer account
    • createLaunchpadOffer - Added method for buyers to request the ordinal from launchpad phase to buy
    • submitLaunchpadOffer - Added method to update the signed PSBT and broadcast the buyer transaction
  • Mempool

    • constructor - Added method constructor for initialization of Mempool instance
    • getFeeEstimation - Added method to gets the recommended fee estimation
    • getAddressUtxo - Added method to Gets the UTXO (unspent transaction outputs) for a given address from the Mempool API.
  • Satextractor

    • constructor - Added method constructor for initialization of satextractor instance
    • extract - Added method to extracts data using the Satextractor API
  • Satscanner

    • constructor - Added method constructor for initialization of Satscanner instance
    • getSupportedSatributes - Added method to Retrieves the supported Satributes
    • findSpecialRanges - Added method to finds special ranges using the Satscanner API
    • findSpecialRangesUtxo - Added method to finds special ranges UTXO using the Satscanner API
  • Ordinalsbot

    • Added Launchpad instance in the Ordinalsbot class
    • Added Mempool instance in the Ordinalsbot class
    • Added Satextractor instance in the Ordinalsbot class
    • Added Satscanner instance in the Ordinalsbot class
    • Added properties for the classes.
    import { Ordinalsbot } from 'ordinalsbot'
    
    // If no parameter is given, the default environment is 'live'
    const ordinalsbotObj = new Ordinalsbot(API_KEY, 'dev')
    const marketPlace = ordinalsbotObj.MarketPlace()
    const inscription = ordinalsbotObj.Inscription()
    const launchpad = ordinalsbotObj.Launchpad()
    const mempool = ordinalsbotObj.Mempool()
    const satextractor = ordinalsbotObj.Satextractor()
    const satscanner = ordinalsbotObj.Satscanner()
    

[0.1.4]

APIs Added

  • Inscription

    • createSpecialSats - Added method to create special sats.

APIs Updated

  • Inscription

    • getPrice - Updated the request and response object.
    • createOrder - Updated the request and response object.
    • createCollection - Updated the request and response object.
    • createCollectionOrder - Updated the request and response object.
    • createTextOrder - Updated the request and response object.
  • Ordinalsbot

    • Updated Usage of Ordinalsbot.
    import { Ordinalsbot } from 'ordinalsbot'
    
    // If no parameter is given, the default environment is 'live'
    const ordinalsbotObj = new Ordinalsbot(API_KEY, 'dev')
    const marketPlace = ordinalsbotObj.MarketPlace
    const inscription = ordinalsbotObj.Inscription
    

[0.1.3]

APIs Updated

  • Marketplace

    • confirmListing - Added method to update the signedPSBT on a newly created listing.
    • reListing - Added method to update the price of existing listing ordinal.
    • confirmReListing - Added method to update the signedPSBT on a new relisting.
    • deList - Added method to remove the existing listing.
    • transfer - Updated the method to support transfer of multiple ordinals.

[0.1.2]

APIs Updated

  • Inscription

    • Added metadata support for insrciption orders.
    • Added brotli compression support for inscription orders.

[0.1.1]

APIs Updated

  • Marketplace

    • createListing - Added walletProvider parameter
    • createOffer - Added walletProvider parameter
    • setupPaddingOutputs - Added walletProvider parameter

[0.1.0]

APIs exposed

  • Inscription

    • constructor
    • getPrice
    • createOrder
    • getOrder
    • createCollection
    • createCollectionOrder
    • createTextOrder
    • getInventory
    • setReferralCode
    • getReferralStatus
  • Marketplace

    • constructor
    • createMarketPlace
    • createListing
    • saveListing
    • getListing
    • createOffer
    • submitOffer
    • confirmPaddingOutputs
    • setupPaddingOutputs