-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: Sending Bitcoin with Hiro Wallet | ||
description: Initiate a basic Bitcoin transaction with the Hiro wallet | ||
--- | ||
|
||
Using Hiro's web wallet, we can easily initiate a simple Bitcoin transaction using only a few lines of code. | ||
|
||
You'll need to be authenticated with the Hiro wallet for this to work, with you can see how to do in the [Authentication with Stacks.js](./stacks-js-auth) recipe. | ||
|
||
Once you have the wallet hooked up, you can use the Hiro wallet API to initiate a simple Bitcoin transaction in your JS app like this. | ||
|
||
```javascript | ||
const sendBitcoin = async () => { | ||
const resp = await window.btc?.request("sendTransfer", { | ||
address: "tb1qya9wtp4dyq67ldxz2pyuz40esvgd0cgx9s3pjl", //replace this with whatever address you want to send to | ||
amount: "10000", // the amount you want to send denoted in satoshis | ||
}); | ||
|
||
// Storing txid in local storage | ||
// We'll get back the transaction IF, which we can then use to do whatever we want | ||
if (typeof window !== "undefined") { | ||
localStorage.setItem("txid", JSON.stringify(resp.result.txid)); | ||
} | ||
|
||
// We may want to do something once this transaction has confirmed, so we can set it to pending here and then use an API like mempool.space to query the Bitcoin chain for information about this transaction | ||
localStorage.setItem("txStatus", "pending"); | ||
}; | ||
``` | ||
Then all we would do is hook up our button to call this `sendBitcoin` function. | ||
```javascript | ||
<button onClick={sendBitcoin}>Send Bitcoin</button> | ||
``` | ||
You can take a look at the [Verifying a transaction on the BTC chain](./verifying-a-btc-tx-was-mined.md) recipe to see a more complex user flow of verifying a transaction was mined using this returned ID as a starting point. | ||
You can take a look at a bit more info about this simple API on the [Hiro wallet developer docs](https://hirowallet.gitbook.io/developers/bitcoin/sign-transactions/sending-bitcoin). |
056f939
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
stacks-docs – ./
blockstack-docs.vercel.app
stacks-docs-stacks-team.vercel.app
docs-staging.blockstack.org
docs.stacks.co
stacks-docs-git-master-stacks-team.vercel.app
docs.blockstack.org