Adding a new Output
I am trying to make a node js app to buy a brc20 token using Unisat market api, I want to add % comission to the psbt i am recieving but when i am making changes to psbt and run the confirmBid api, i get this error "Error: User params error" , Maybe i am implementing it wrong. How extactly will i do it?
This is the code const data = await marketApi.createBid({ auctionId: item.auctionId, bidPrice: item.price, address: wallet.address, pubkey: wallet.pubkey, });
// console.log(data); const psbt = bitcoin.Psbt.fromHex(data.psbtBid, { network: bitcoin.networks.testnet, });
console.log("total_value: " + total_value); let our_fee = Math.round(total_value * 0.01);
psbt.data.inputs[5].witnessUtxo.value += our_fee; // adding fee to the last input
psbt.addOutput({ address: "tb1qanqrh5dfdc0dv38y4dej2xqqysvrzd87k9anj0", value: our_fee, });
const signedPsbt = await wallet.signPsbt(psbt, { autoFinalized: false, });
await marketApi.confirmBid({ auctionId: item.auctionId, bidId: data.bidId, psbtBid: psbt.toHex(), psbtBid2: "", psbtSettle: "", fromBase64: false, }); console.log("Confirmed");
Currently, the PSBT in the API cannot be modified. We will consider supporting the addition of extra fees directly in the API soon.