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('0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a. ( 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 之前我們需要發送一些比特幣到這個地址。 .address) ; // 'tb1p5mykwcq5ly7y2ctph9r2wfgldq94eccm2t83dd58k785p0zqzwkspyjkp5'// 要格外小心:有可能意外地發送銘文作為費用。 = RevealPayment.address; // 可以不同 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<字串,Uint8Array>;元資料:P.CoderType<任意>;元協定:P.CoderType<字串>;內容編碼:P.CoderType<字串>;委託:P.Coder<字串,Uint8Array>;符文:P. CoderType<bigint>;注意:P.CoderType<string>;};導出型別Tags = Partial<{[K in keyof typeof TagCoders]: P.UnwrapCoder<(typeof TagCoders)[K ]>;}> & {未知?正文:位元組;被詛咒了? }; 類型 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),請參閱許可證文件。