You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rust/basic_bitcoin/README.md
+44-39Lines changed: 44 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,74 +2,85 @@
2
2
3
3
This example demonstrates how to deploy a smart contract on the Internet Computer that can receive and send bitcoin, including support for legacy (P2PKH), SegWit (P2WPKH), and Taproot (P2TR) address types.
4
4
5
-
This example also includes examples of how to work with Bitcoin assets such as Ordinals, Runes, and BRC-20 tokens.
5
+
This example also includes how to work with Bitcoin assets such as Ordinals, Runes, and BRC-20 tokens.
6
6
7
7
## Table of contents
8
8
9
-
-[Architecture](#architecture)
10
-
-[Prerequisites](#prerequisites)
11
-
-[Building and deploying the smart contract](#building-and-deploying-the-smart-contract)
For background on the ICP<>BTC integration, refer to the [Learn Hub](https://learn.internetcomputer.org/hc/en-us/articles/34211154520084-Bitcoin-Integration).
-[x] On macOS, an `llvm` version that supports the `wasm32-unknown-unknown` target is required. This is because the Rust `bitcoin` library relies on the `secp256k1-sys` crate, which requires `llvm` to build. The default `llvm` version provided by XCode does not meet this requirement. Instead, install the [Homebrew version](https://formulae.brew.sh/formula/llvm), using `brew install llvm`.
40
42
41
43
## Deploying from ICP Ninja
42
44
43
-
This example can be deployed directly to the Internet Computer using ICP Ninja, where it will connect to Bitcoin **testnet4**. Note: Canisters deployed using ICP Ninja remain live for 50 minutes after signing in with your Internet Identity (accessible via the top-right button in ICP Ninja).
45
+
This example can be deployed directly to the Internet Computer using ICP Ninja, where it connects to Bitcoin **testnet4**. Note: Canisters deployed via ICP Ninja remain live for 50 minutes after signing in with your Internet Identity.
*[x] On macOS, an `llvm` version that supports the `wasm32-unknown-unknown` target is required. The Rust `bitcoin` library relies on the `secp256k1-sys` crate, which requires `llvm` to build. The default `llvm` version provided by XCode does not meet this requirement. Install the [Homebrew version](https://formulae.brew.sh/formula/llvm) using `brew install llvm`.
57
+
58
+
59
+
### 2. Clone the examples repo
50
60
51
61
```bash
52
62
git clone https://github.com/dfinity/examples
53
63
cd examples/rust/basic_bitcoin
54
64
```
55
65
56
-
### 2. Start the ICP execution environment
66
+
### 3. Start the ICP execution environment
67
+
57
68
58
69
Open a terminal window (terminal 1) and run the following:
Open a third terminal (terminal 3) and run the following to deploy the smart contract:
75
86
@@ -83,7 +94,6 @@ What this does:
83
94
-`--argument '(variant { regtest })'` passes the argument `regtest` to initialize the smart contract, telling it to connect to the local Bitcoin regtest network.
84
95
85
96
Your smart contract is live and ready to use! You can interact with it using either the command line or the Candid UI (the link you see in the terminal).
86
-
87
97
## Generating Bitcoin addresses
88
98
89
99
The example demonstrates how to generate and use the following address types:
@@ -92,35 +102,32 @@ The example demonstrates how to generate and use the following address types:
92
102
2.**P2WPKH (SegWit v0)** using ECDSA and `sign_with_ecdsa`
93
103
3.**P2TR (Taproot, key-path-only)** using Schnorr keys and `sign_with_schnorr`
94
104
4.**P2TR (Taproot, script-path-enabled)** commits to a script allowing both key path and script path spending
95
-
96
-
Use the Candid UI or command line to generate these addresses with:
105
+
Use the Candid UI or CLI to generate:
97
106
98
107
```bash
99
108
dfx canister call basic_bitcoin get_p2pkh_address
100
-
# or get_p2wpkh_address, get_p2tr_key_path_only_address, get_p2tr_script_path_enabled_address
This calls `bitcoin_get_block_headers`, which is useful for blockchain validation or light client logic.
168
-
169
175
## Bitcoin assets
170
176
171
177
Bitcoin's scripting capabilities enable various digital assets beyond simple transfers. This example demonstrates how to create and interact with three major Bitcoin asset protocols from an ICP smart contract:
@@ -307,7 +313,6 @@ The deployment inscription contains JSON metadata that BRC-20 indexers use to tr
307
313
308
314
To view the deployed BRC-20 token, use the local `ord` explorer at `http://127.0.0.1:80/`.
309
315
310
-
311
316
## Notes on implementation
312
317
313
318
This example implements several important patterns for Bitcoin integration:
@@ -331,4 +336,4 @@ For example, the following aspects are particularly relevant for this app:
0 commit comments