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

Method mintP2TRNote

src/btc/btc-wallet.ts:172–228  ·  view source on GitHub ↗
(
    payload: NotePayload,
    tokenAddresses: ISendToAddress[] | ISendToScript[],
    noteUtxos: IUtxo[],
    payUtxos?: IUtxo[],
    feePerKb?: number,
    locktime?: number
  )

Source from the content-addressed store, hash-verified

170 }
171
172 async mintP2TRNote(
173 payload: NotePayload,
174 tokenAddresses: ISendToAddress[] | ISendToScript[],
175 noteUtxos: IUtxo[],
176 payUtxos?: IUtxo[],
177 feePerKb?: number,
178 locktime?: number
179 ) {
180 payUtxos = payUtxos ?? (await this.fetchAllAccountUtxos());
181 feePerKb = feePerKb ?? (await this.getFeePerKb()).avgFee;
182 const network =
183 bitcoin.networks[
184 this.config.network === "livenet" ? "bitcoin" : "testnet"
185 ];
186
187 const privateKeyBuffer = new PrivateKey(
188 this.currentAccount.privateKey
189 ).toBuffer();
190 const privateKey = ECPair.fromPrivateKey(privateKeyBuffer);
191
192 const estimatedPsbt = createP2TRNotePsbt(
193 privateKey,
194 payload,
195 noteUtxos,
196 payUtxos,
197 tokenAddresses as ISendToAddress[],
198 this.currentAccount.mainAddress!.address!,
199 network,
200 1000,
201 locktime
202 );
203
204 const estimatedSize = estimatedPsbt.virtualSize();
205 const realFee = Math.floor((estimatedSize * feePerKb) / 1000 + 1);
206
207 const finalTx = createP2TRNotePsbt(
208 privateKey,
209 payload,
210 noteUtxos,
211 payUtxos,
212 tokenAddresses as ISendToAddress[],
213 this.currentAccount.mainAddress!.address!,
214 network,
215 realFee,
216 locktime
217 );
218
219 return {
220 txId: finalTx.getId(),
221 txHex: finalTx.toHex(),
222 psbtHex: estimatedPsbt.toHex(),
223 noteUtxos,
224 payUtxos,
225 feePerKb,
226 realFee,
227 };
228 }
229

Callers 1

buildNoteTransactionMethod · 0.95

Calls 2

getFeePerKbMethod · 0.95
createP2TRNotePsbtFunction · 0.90

Tested by

no test coverage detected