MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / mintP2TRNoteV1

Method mintP2TRNoteV1

src/btc/btc-wallet.ts:439–527  ·  view source on GitHub ↗
(payload: NotePayload, to: string, noteUtxos?: IUtxo[])

Source from the content-addressed store, hash-verified

437 }
438
439 async mintP2TRNoteV1(payload: NotePayload, to: string, noteUtxos?: IUtxo[]) {
440 if (undefined === noteUtxos) {
441 noteUtxos = await this.urchain.utxos([
442 this.currentAccount.addressP2TRNoteV1.scriptHash,
443 ]);
444 if (noteUtxos.length === 0) {
445 const result = await this.send([
446 {
447 address: this.currentAccount.addressP2TRNoteV1.address!,
448 amount: MIN_SATOSHIS,
449 },
450 ]);
451 if (result.success) {
452 for (let i = 0; i < 10; i++) {
453 noteUtxos = await this.urchain.utxos([
454 this.currentAccount.addressP2TRNoteV1.scriptHash,
455 ]);
456 if (noteUtxos.length > 0) {
457 break;
458 } else if (i === 9) {
459 throw new Error("can not get note utxo");
460 }
461 await sleep(1000);
462 }
463 } else {
464 throw new Error(result.error);
465 }
466 }
467 for (const utxo of noteUtxos) {
468 utxo.type = "P2TR-NOTE-V1";
469 }
470 }
471 if (undefined === to) {
472 to = this.currentAccount.tokenAddress!.address!;
473 }
474 const toAddress: ISendToAddress = {
475 address: to,
476 amount: MIN_SATOSHIS,
477 };
478 const toAddresses = [toAddress];
479
480 const payUtxos = await this.fetchAllAccountUtxos();
481
482 const feeRate = (await this.getFeePerKb()).avgFee;
483
484 const network =
485 bitcoin.networks[
486 this.config.network === "livenet" ? "bitcoin" : "testnet"
487 ];
488
489 const privateKeyBuffer = new PrivateKey(
490 this.currentAccount.privateKey
491 ).toBuffer();
492 const privateKey = ECPair.fromPrivateKey(privateKeyBuffer);
493
494 const estimatedPsbt = createP2TRNotePsbtV1(
495 privateKey,
496 payload,

Callers 1

upN20Method · 0.95

Calls 5

sendMethod · 0.95
getFeePerKbMethod · 0.95
sleepFunction · 0.90
createP2TRNotePsbtV1Function · 0.90
utxosMethod · 0.80

Tested by

no test coverage detected