Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const fetchFee = async ({ to, from, privateKey, amount }) => {
const fromAddress = Address.fromString(from);
const toAddress = Address.fromString(to);
const utxos = await getUnspentUtxos(fromAddress);
const tx = generateTx({
utxos,
fromAddress,
toAddress,
privateKey,
amount,
});
const { inputs, outputs } = tx.toObject();
const totalInputs = inputs.reduce((p, c) => p + c.output.satoshis, 0);
const totalOutputs = outputs.reduce((p, c) => p + c.satoshis, 0);
const fee = totalInputs - totalOutputs;
return toBTC(fee);
};
export const broadcast = async ({ to, from, privateKey, amount }) => {
const fromAddress = Address.fromString(from);
const toAddress = Address.fromString(to);
const utxos = await getUnspentUtxos(fromAddress);
const tx = generateTx({
utxos,
fromAddress,
toAddress,
privateKey,
amount,
});
return await broadcastTx(tx);
};