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

Method sendEstimate

src/btc/btc-wallet.ts:102–126  ·  view source on GitHub ↗
(toAddresses: ISendToAddress[], feePerKb?: number)

Source from the content-addressed store, hash-verified

100 }
101
102 async sendEstimate(toAddresses: ISendToAddress[], feePerKb?: number) {
103 const utxos = await this.fetchAllAccountUtxos();
104 feePerKb = feePerKb ?? (await this.getFeePerKb()).avgFee;
105 const network =
106 bitcoin.networks[
107 this.config.network === "livenet" ? "bitcoin" : "testnet"
108 ];
109
110 const privateKeyBuffer = new PrivateKey(
111 this.currentAccount.privateKey
112 ).toBuffer();
113 const privateKey = ECPair.fromPrivateKey(privateKeyBuffer);
114
115 const estimatedPsbt = createCoinPsbt(
116 privateKey,
117 utxos,
118 toAddresses,
119 this.currentAccount.mainAddress!.address!,
120 network,
121 1000
122 );
123
124 const estimatedSize = estimatedPsbt.virtualSize();
125 return Math.floor((estimatedSize * feePerKb) / 1000 + 1);
126 }
127
128 async send(toAddresses: ISendToAddress[], feePerKb?: number) {
129 const utxos = await this.fetchAllAccountUtxos();

Callers 1

sendMethod · 0.95

Calls 2

getFeePerKbMethod · 0.95
createCoinPsbtFunction · 0.90

Tested by

no test coverage detected