How to Build a BRC20 Ordinal Marketplace

·

As Bitcoin continues to evolve beyond its original purpose as a peer-to-peer digital currency, new protocols like Ordinals and BRC20 are unlocking innovative ways to tokenize and trade digital assets directly on the Bitcoin blockchain. These technologies allow developers to create decentralized marketplaces where users can buy, sell, and trade unique tokenized assets—such as digital collectibles or fungible tokens—without relying on smart contract platforms like Ethereum.

This comprehensive guide walks you through the technical process of building a BRC20 Ordinal marketplace using Partially Signed Bitcoin Transactions (PSBT) and the bitcoinjs-lib library. You'll learn how to securely facilitate token exchanges between buyers and sellers in a trustless, decentralized environment.


Understanding BRC20 and Ordinals

Before diving into development, it's essential to understand the core technologies enabling this ecosystem:

Together, these innovations make it possible to represent and exchange digital assets natively on Bitcoin, opening doors for decentralized marketplaces.

👉 Discover how blockchain developers are leveraging Bitcoin’s native protocols for next-gen applications.


Prerequisites

To follow along with this tutorial, ensure you have the following:

Install the required dependencies:

npm install bitcoinjs-lib bip32 tiny-secp256k1

These tools will enable transaction construction, wallet management, and cryptographic operations.


Step 1: Setting Up Your Development Environment

Start by initializing a new Node.js project:

mkdir ordinal-marketplace
cd ordinal-marketplace
npm init -y
npm install bitcoinjs-lib bip32 tiny-secp256k1

This sets up a clean environment for building and testing PSBT-based transactions.


Step 2: Crafting a PSBT for BRC20 Token Exchange

The heart of any secure marketplace lies in its transaction workflow. Using PSBTs ensures that multiple parties (e.g., buyer and seller) can collaboratively construct and sign a transaction without exposing private keys.

Initialize the PSBT

const bitcoin = require('bitcoinjs-lib');
const network = bitcoin.networks.testnet; // Use 'bitcoin' for mainnet
const psbt = new bitcoin.Psbt({ network });

Using testnet allows safe experimentation before deploying to mainnet.

Add Inputs: Buyer’s UTXO

The buyer must provide an unspent output to fund the purchase:

psbt.addInput({
  hash: buyerInscriptionWithUtxo.txid,
  index: buyerInscriptionWithUtxo.vout,
  witnessUtxo: {
    value: buyerInscriptionWithUtxo.value,
    script: buyerScriptpubkey,
  },
  tapInternalKey: Buffer.from(buyerPubkey, "hex").slice(1, 33),
});

This input represents the buyer’s contribution—typically including both payment and change handling.

Add Outputs: Payment and Ordinal Transfer

Two outputs are needed:

  1. Payment to seller in satoshis.
  2. Transfer of the inscribed satoshi (containing the BRC20 token) to the buyer.
// Seller receives payment
psbt.addOutput({
  address: 'seller-bitcoin-address',
  value: 50000 // e.g., 0.0005 BTC
});

// Buyer receives the BRC20 Ordinal inscription
psbt.addOutput({
  address: 'buyer-bitcoin-address',
  value: 1 // The specific satoshi with inscription
});

This structure ensures atomicity: either both transfers happen, or the entire transaction fails.


Step 3: Signing the Transaction

A PSBT requires signatures from all involved parties to be valid.

Buyer Signs First

const { ECPair } = bitcoin;
const buyerKeyPair = ECPair.fromWIF('buyer-private-key', network);
psbt.signInput(0, buyerKeyPair);
psbt.validateSignaturesOfInput(0);

Seller Adds Their Signature

The seller signs their part (e.g., releasing control of the inscribed satoshi):

const sellerKeyPair = ECPair.fromWIF('seller-private-key', network);
psbt.signInput(1, sellerKeyPair); // Assuming seller owns input
psbt.validateSignaturesOfInput(1);

Once both parties sign, finalize the inputs:

psbt.finalizeAllInputs();

Step 4: Broadcasting the Transaction

After combining all signatures, extract the final transaction and broadcast it:

const tx = psbt.extractTransaction();
console.log(`Transaction Hex: ${tx.toHex()}`);

You can submit the raw hex via:

Upon confirmation, the BRC20 token is transferred, and the seller receives payment.

👉 Learn how developers use secure transaction patterns to power decentralized marketplaces.


Step 5: Building Marketplace Features

Now that you’ve mastered individual transactions, scale into a full-fledged BRC20 Ordinal marketplace with these key components:

✅ Token Listings

Allow sellers to list their inscribed BRC20 tokens with metadata (name, symbol, image) and set prices in BTC.

✅ Escrow Mechanism

Implement multi-signature wallets or time-locked contracts to hold funds securely until delivery is confirmed.

✅ Order Book System

Maintain an order book tracking active buy/sell orders, enabling price discovery and automated matching.

✅ Frontend dApp Interface

Build a user-friendly web interface using React or Vue.js, connecting to Bitcoin nodes via libraries like bitcoinjs-lib or indexing services like Ordinal Studio or Gamma.io.

Backend logic should handle PSBT generation, signature collection, and broadcasting—ensuring seamless user experience.


Frequently Asked Questions (FAQ)

What is a BRC20 token?

BRC20 is a fungible token standard built on Bitcoin using Ordinal inscriptions. It allows issuance and transfer of tokens directly on Bitcoin without sidechains or layer-2 solutions.

How does an Ordinal marketplace work?

Users list inscribed satoshis (with BRC20 data) for sale. Buyers initiate PSBTs to purchase them. After mutual signing, the transaction is broadcasted, transferring ownership securely.

Can I build this on Bitcoin mainnet?

Yes. While this guide uses testnet for safety, all steps apply to mainnet. Always double-check addresses and values before going live.

Is PSBT necessary for BRC20 transfers?

While not strictly mandatory, PSBT is highly recommended for multi-party transactions. It supports offline signing, enhances security, and enables trustless exchanges.

What are the fees involved?

Transaction fees depend on size (in vBytes) and network congestion. Since Ordinal inscriptions can be large, expect higher fees than typical Bitcoin transfers.

How do I track BRC20 balances?

Use dedicated indexers like Ordinal Theory, Gamma, or Ord.io, which scan the blockchain and maintain databases of inscriptions and token holdings.


Conclusion

Building a BRC20 Ordinal marketplace represents a powerful convergence of Bitcoin’s immutability and emerging tokenization standards. By leveraging PSBTs and libraries like bitcoinjs-lib, developers can create secure, decentralized platforms for trading digital assets directly on Bitcoin.

As adoption grows, so does the potential for innovation—from NFT-like collectibles to tokenized real-world assets—all anchored in Bitcoin’s robust security model.

Whether you're exploring decentralized finance, digital ownership, or blockchain development trends in 2025, mastering BRC20 and Ordinals positions you at the forefront of Bitcoin’s evolving ecosystem.

👉 Explore cutting-edge tools and resources for building on Bitcoin today.