How to Build a BRC20 Ordinal Marketplace

·

The Bitcoin blockchain has evolved far beyond its original purpose as a peer-to-peer electronic cash system. With innovations like Ordinals and the BRC20 token standard, developers can now issue, inscribe, and trade digital assets directly on Bitcoin—ushering in a new era of decentralized marketplaces. These technologies allow for the creation of fungible tokens (BRC20) and unique, data-embedded satoshis (Ordinals), enabling a trustless environment where users exchange valuable digital collectibles and tokenized assets.

This guide walks you through building a BRC20 Ordinal marketplace using Partially Signed Bitcoin Transactions (PSBT) and the bitcoinjs-lib library. You’ll learn how to securely facilitate multi-party transactions, transfer BRC20 tokens via Ordinal inscriptions, and lay the foundation for a scalable, decentralized trading platform on Bitcoin.

Core Keywords


Setting Up Your Development Environment

Before diving into transaction construction, ensure your development environment is properly configured:

👉 Discover how developers are leveraging Bitcoin’s latest innovations to build next-gen marketplaces.


Understanding BRC20 and Ordinal Integration

The BRC20 standard enables the issuance and transfer of fungible tokens on the Bitcoin blockchain, similar in concept to Ethereum’s ERC20. However, unlike Ethereum, Bitcoin does not natively support smart contracts. Instead, BRC20 relies on Ordinal inscriptions—data written directly onto individual satoshis—to represent token ownership and transfers.

Each BRC20 token operation (deploy, mint, transfer) is encoded as a JSON payload inscribed via an Ordinal. When a user wants to transfer a BRC20 token, they're actually transferring the specific satoshi that contains the inscription confirming their ownership.

In our marketplace scenario, imagine a buyer purchasing a BRC20 token from a seller. The transaction must securely:

To achieve this trustlessly, we use PSBTs—a standardized format for constructing transactions that require multiple signatures.


Step-by-Step: Crafting a PSBT for BRC20 Transfer

Initialize the PSBT

Start by setting up a new PSBT instance using bitcoinjs-lib. For testing, use Bitcoin’s testnet; switch to mainnet when ready for production.

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

Add Inputs: Buyer’s UTXO

The buyer contributes BTC to pay for the BRC20 token. We add their UTXO as an input, including necessary metadata like script and value.

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 funds being spent and includes taproot signing requirements.

Add Outputs: Payment and Token Transfer

We define two outputs:

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

// Output 2: Buyer receives the inscribed satoshi (BRC20 token)
psbt.addOutput({
  address: 'buyer-bitcoin-address',
  value: 1 // Exactly one satoshi carrying the inscription
});

This structure ensures atomicity—the token and payment are exchanged together within a single transaction.


Signing the Transaction Securely

For the transaction to be valid, both parties must sign:

Buyer Signs First

The buyer signs their input to authorize spending their UTXO.

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

Seller Signs to Release the Token

The seller signs to acknowledge receipt of payment and confirm transfer of the inscribed satoshi. Their signature locks in the second part of the agreement.

Once both signatures are applied, the PSBT is finalized.


Combining and Broadcasting the Transaction

After both parties sign, combine the partial signatures into one PSBT:

const psbt = Bitcoin.Psbt.fromHex(hexedPsbt);
const signedPsbt1 = Bitcoin.Psbt.fromHex(signedHexedPsbt1);

if (signedHexedPsbt2) {
  const signedPsbt2 = Bitcoin.Psbt.fromHex(signedHexedPsbt2);
  psbt.combine(signedPsbt1, signedPsbt2);
} else {
  psbt.combine(signedPsbt1);
}

// Extract fully signed transaction
const tx = psbt.extractTransaction();
console.log(`Transaction Hex: ${tx.toHex()}`);

Broadcast the resulting raw transaction hex using a Bitcoin node or API like Blockstream’s sendtx.

👉 See how top developers streamline Bitcoin-based transactions with advanced tooling.


Building Marketplace Logic

With core transaction mechanics in place, expand into a full-featured decentralized marketplace:

📦 Token Listings

Allow sellers to list BRC20 tokens with metadata (name, symbol, inscription ID) and set prices in BTC.

🔐 Escrow System

Use multi-sig wallets or PSBT coordination services to hold funds until both parties fulfill obligations—preventing fraud.

📊 Order Book

Maintain an on-chain or off-chain order book showing active buy/sell orders, recent trades, and price history.

🖥️ Frontend dApp Interface

Build a user-friendly interface where buyers can browse listings, view inscriptions, and initiate trades seamlessly.

All transaction logic should run in a secure backend service that generates PSBTs, coordinates signing, and broadcasts final transactions.


Frequently Asked Questions

What is a BRC20 token?

BRC20 is an experimental token standard on Bitcoin that uses Ordinal inscriptions to issue and transfer fungible tokens. Operations like deploy, mint, and transfer are encoded as JSON payloads written onto satoshis.

How do Ordinals enable NFT-like functionality on Bitcoin?

Ordinals assign unique identities to individual satoshis. By inscribing data (images, text, code) onto them, users create non-fungible digital artifacts—similar to NFTs—that can be transferred across wallets.

Why use PSBTs in a BRC20 marketplace?

PSBTs allow multiple parties to collaboratively construct and sign transactions without exposing private keys. This enables secure peer-to-peer trading of BRC20 tokens without centralized intermediaries.

Can BRC20 tokens be traded directly on Bitcoin?

Yes. Since BRC20 relies on Ordinal inscriptions stored on-chain, transfers occur via standard Bitcoin transactions that move specific UTXOs containing inscribed data.

Is it safe to build a marketplace using bitcoinjs-lib?

bitcoinjs-lib is one of the most widely used and audited libraries for Bitcoin development. When used correctly—with proper key management and input validation—it provides robust security for handling transactions.

How do I prevent double-spending of inscribed satoshis?

Ensure your application tracks UTXO status in real time using a block explorer API or full node. Always verify that an inscribed satoshi hasn’t been spent before including it in a new transaction.


Conclusion

Building a BRC20 Ordinal marketplace unlocks new possibilities for decentralized asset trading on Bitcoin. By combining Ordinals, BRC20, and PSBT workflows, developers can create secure, trustless platforms where users exchange tokenized digital assets directly on-chain.

As adoption grows, so will demand for robust infrastructure—wallet integrations, indexing services, and developer tools—that support these emerging standards. Mastering PSBT-based transaction flows today positions you at the forefront of Bitcoin’s evolving ecosystem.

Whether you're launching a niche NFT gallery or scaling a full-fledged exchange, understanding how to manage inscriptions, craft atomic swaps, and integrate secure signing workflows is essential.

👉 Start experimenting with Bitcoin’s newest capabilities and build your own marketplace today.