The Bitcoin transaction builder for Bitcoin Stamps and SRC-20 metaprotocols
Build Bitcoin transactions with native support for Bitcoin Stamps, SRC-20 tokens, Ordinals protection, and extensible metaprotocol support.
Installation โข Quick Start โข Examples โข Documentation โข API Reference
@btc-stamps/tx-builder is the only transaction builder with first-class support for Bitcoin Stamp metaprotocols. This can be extended to support other metaprotocols like Runes or BRC-20.
sideEffects: falsenpm install @btc-stamps/tx-builder
# or
yarn add @btc-stamps/tx-builder
# or
pnpm add @btc-stamps/tx-builder
import { TransactionBuilder } from 'npm:@btc-stamps/tx-builder@^0.1.6';
import { BitcoinStampBuilder, SelectorFactory } from '@btc-stamps/tx-builder';
// Zero-config setup with automatic UTXO protection
const selectorFactory = SelectorFactory.getInstance();
const builder = new BitcoinStampBuilder(network, selectorFactory);
// Build stamp transaction - automatically protects:
// โ
Ordinals (sats with inscriptions or runes)
// โ
Bitcoin Stamps (all types)
// โ
Counterparty assets (XCP, PEPECASH, etc.)
// โ
SRC-20 tokens
const result = await builder.buildStampTransaction(utxos, {
stampData: {
imageData: imageBuffer,
filename: 'my-stamp.png',
},
fromAddress: 'bc1q...',
feeRate: 20,
algorithm: 'protection-aware', // Optional: explicitly use protection-aware selection
});
import { SRC20Encoder, SRC20TokenBuilder } from '@btc-stamps/tx-builder';
const encoder = new SRC20Encoder();
// Deploy new token
const deployData = await encoder.encode({
p: 'SRC-20',
op: 'DEPLOY',
tick: 'KEVIN',
max: '21000000',
lim: '1000',
});
// Build transaction
const psbt = await new SRC20TokenBuilder().buildSRC20Transaction({
encodedData: deployData,
utxos: selectedUTXOs,
changeAddress: 'bc1q...',
feeRate: 15,
});
Built-in protection for Ordinals, Inscriptions, Stamps, Counterparty assets, and SRC-20 tokens is automatic in all builders.
// For custom protection configuration:
const selector = selectorFactory.createSelector('protection-aware', {
protectionConfig: {
enableOrdinalsDetection: true, // Detect inscriptions and runes
enableCounterpartyDetection: true, // Detect UTXO attached assets
enableStampsDetection: true, // Detect UTXO attached stamps
},
});
// Use with any builder
builder.setSelector(selector);
Optimize transaction fees with multiple selection strategies:
import {
AccumulativeSelector, // Fast selection
BlackjackSelector, // Target exact amounts
BranchAndBoundSelector, // Optimal selection
WasteOptimizedSelector, // Long-term optimization
} from '@btc-stamps/tx-builder';
Zero-configuration with reliable defaults:
// Works immediately - no setup required
const provider = new ElectrumXProvider(); // Uses blockstream.info, fortress.qtornado.com, etc.
Networks: Mainnet, Testnet, Regtest with automatic server selection
npm test # Run all tests
npm run test:unit # Unit tests only
npm run test:coverage # Coverage report
Contributions welcome! See Contributing Guide for details.
# Clone the repository
git clone https://github.com/btc-stamps/tx-builder.git
cd tx-builder
# Install dependencies
npm install
# Run tests
npm test
# Build the package
npm run build
MIT License - see LICENSE file.
Built on top of excellent libraries:
GitHub: btc-stamps/tx-builder โข NPM: @btc-stamps/tx-builder โข JSR: @btc-stamps/tx-builder โข Telegram: @BitcoinStamps
Built with โค๏ธ by the Stampchain team