scure-btc-signer 之上的序数和铭文的最小 JS 库。
将其用作 JS 代码中的库,或运行附带的 CLI 工具。铭文允许在 BTC 区块链上上传随机文件。
实验性:在彻底测试之前可能会导致资金损失。
npm install 微序数
创建铭文
TypeScript API
命令行界面
// npm install micro-ordinals @scure/btc-signer @scure/baseimport * as btc from '@scure/btc-signer';import * as ordinals from 'micro-ordinals';import { hex, utf8 } from '@ scure/base';const TESTNET = btc.utils.TEST_NETWORK;const privKey = hex.decode('0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a');const pubKey = btc.utils.pubSchnorr(privKey);const customScripts = [ordinals.OutOrdinalReveal]; // 在外部启用自定义脚本// 这会刻在第一个输入的第一个聪上(默认)const inscription = { Tags: {contentType: 'application/json', // 可以是任何格式(MIME 类型)// ContentEncoding: 'br', // 压缩:仅支持 brotli }, body: utf8.decode(JSON.stringify({ some: 1, test: 2, inscription: true, in: 'json' })), // 可以在html中使用之前写好的js脚本 // utf8.decode(`<html><head></head><body><script src="/content/script_inscription_id"></script>test</html>`)};const RevealPayment = btc.p2tr ( undefined, // 内部公钥 ordinals.p2tr_ord_reveal(pubKey, [inscription]), // TaprootScriptTree TESTNET, // 主网或测试网 false, // 允许未知输出,安全功能 customScripts // 如何处理自定义脚本);// 在 Reveal 之前我们需要发送一些比特币到这个地址。 // 另外,应该有足够的比特币来覆盖 Reveal tx Fee.console.log('Address', RevealPayment.address) ; // 'tb1p5mykwcq5ly7y2ctph9r2wfgldq94eccm2t83dd58k785p0zqzwkspyjkp5'// 要格外小心:有可能意外地发送铭文作为费用。// 另外,稀有度仅适用于序号钱包。// 但您可以解析其他铭文并使用它创建一个通用铭文。常量更改地址= RevealPayment.地址; // 可以不同 const RevealAmount = 2000n;const Fee = 500n;const tx = new btc.Transaction({ customScripts });tx.addInput({ ...显示付款, // 这是我们发送的比特币的 tx txid(替换) txid: '75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858', 索引:0, 证人Utxo:{脚本:revealPayment.script,金额:revealAmount },}); tx.addOutputAddress(changeAddr,revealAmount - 费用,TESTNET); tx.sign(privKey,未定义,新Uint8Array(32)); tx.finalize() ;const txHex = hex.encode(tx.extract());console.log(txHex); // 将 tx 显示为广播的十六进制 const tx2 = btc.Transaction.fromRaw(hex.decode(txHex)); // 解析 inscriptionsconsole.log('parsed', ordinals.parseWitness(tx2.inputs[0].finalScriptWitness));console.log('vsize', tx2.vsize); // 显示 tx 至少应该支付这么多费用
import { Coder } from '@scure/base';import * as P from 'micro-packed';import { ScriptType, OptScript, CustomScript } from '@scure/btc-signer';type Bytes = Uint8Array;export 声明 const InscriptionId : P.Coder<string, Bytes>;type TagRaw = {tag: Bytes;data: Bytes;};声明 const TagCoders: {指针: P.CoderType<bigint>;contentType: P.CoderType<string>;父级: P.Coder<string, Uint8Array>;元数据: P.CoderType<any>;元协议: P.CoderType<string>; contentEncoding:P.CoderType<string>;委托:P.Coder<string,Uint8Array>;符文:P.CoderType<bigint>;注意: P.CoderType<string>;};导出类型 Tags = Partial<{[K in keyof typeof TagCoders]: P.UnwrapCoder<(typeof TagCoders)[K]>;}> & {unknown?: [Bytes, Bytes][ ];};导出类型 Inscription = { 标签: 标签;正文:字节;被诅咒了?:布尔值; }; 类型 OutOrdinalRevealType = { 类型: 'tr_ord_reveal';公钥:字节;铭文:铭文[]; };导出声明 const OutOrdinalReveal: Coder<OptScript, OutOrdinalRevealType | undefined> & CustomScript;导出声明函数 parseInscriptions(script: ScriptType, strict?: boolean): Inscription[] | undefined;/** * 解析来自 Reveal tx 输入见证的铭文 (tx.inputs[0].finalScriptWitness) */export 声明函数 parseWitness(witness: Bytes[]): Inscription[] | undefined;/** * 创建揭示交易。 * 通过显示主根脚本在该地址的支出输出上创建的铭文。 */导出声明函数 p2tr_ord_reveal(pubkey: Bytes, inscriptions: Inscription[]): {type: string;script: Uint8Array;};
npm install -g 微序数 ord file.jpg
用法:ord [--net mainnet|testnet] [--priv key] [--recovery key] [--compress=on|off] [--fee 10.1] [--addr 地址]
网络:比特币网络
priv:WIF格式的taproot私钥,将用于揭示交易不要使用你的钱包,priv应该是一个新的。如果没有提供,我们会生成一个临时密钥
恢复:WIF格式的taproot私钥,可用于恢复任何意外发送到铭文地址的比特币,而无需支付全额铭文费用。
压缩:用 brotli 压缩的铭文。与探索者兼容。默认=开
费用:以聪为单位的比特币网络费用
addr:揭示后将发送铭文的地址 重要提示:第一个星期六始终被铭文。不支持批量刻录。
没有网络代码。它使包更安全,但降低了开发人员的体验。
我们或许可以自动收取费用,但 utxo 选择会变得更加复杂。例如,如果用户之前记下了某些内容或具有罕见的序数,我们需要访问序数节点才能知道这一点。此外,我们对钱包中冻结的输出一无所知:它仅位于钱包内部。
要记住的边缘情况:
用户添加了错误的 txid/index 或发送后退出应用程序
我们打印临时私钥,用户可以通过提供“--priv”来重新启动
只要费用/网络/路径相同,您就可以重新启动流程
用户发送的 UTXO 数量少于或多个。
这实际上更难,因为任何支出都需要全额铭文费
为此我们添加recovery
使用 mempool 和 ordinalsbot。
水龙头有几种:uo1、eu、pump
要在 Mac 上使用 Sparrow:
open /Applications/Sparrow.app --args -n testnet
麻省理工学院 (c) Paul Miller (https://paulmillr.com),请参阅许可证文件。