Sending Bitcoin with Leather

Using Leather's web wallet, you can initiate a simple Bitcoin transaction from a JS app in a few lines of code.
1
Prepare the send call
Use the window.btc?.request("sendTransfer", ...) API to initiate a transaction. Provide the destination address and the amount in satoshis.
const sendBitcoin = async () => {
const resp = await window.btc?.request("sendTransfer", {
address: "tb1qya9wtp4dyq67ldxz2pyuz40esvgd0cgx9s3pjl", // replace with the recipient address
amount: "10000", // amount in satoshis
});
// Storing txid in local storage
// We'll get back the transaction ID, which we can then use as needed
if (typeof window !== "undefined") {
localStorage.setItem("txid", JSON.stringify(resp.result.txid));
}
// Optionally mark the transaction as pending and poll a Bitcoin API (e.g., mempool.space) to check confirmation status
localStorage.setItem("txStatus", "pending");
};2
Last updated
Was this helpful?
