Skip to content

Commit 5fcbba3

Browse files
Merge pull request #1164 from dfinity/kristofer/basic_bitcoin_0612
README updates basic_bitcoin
2 parents 787bf15 + e200b7c commit 5fcbba3

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

rust/basic_bitcoin/README.md

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ This example integrates with the Internet Computer's built-in:
1010
- [Schnorr API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr)
1111
- [Bitcoin API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md)
1212

13-
For background on the ICP <-> BTC integration, refer to the [Learn Hub](https://learn.internetcomputer.org/hc/en-us/articles/34211154520084-Bitcoin-Integration).
13+
For background on the ICP<>BTC integration, refer to the [Learn Hub](https://learn.internetcomputer.org/hc/en-us/articles/34211154520084-Bitcoin-Integration).
1414

1515
## Prerequisites
1616

1717
- [x] [Rust toolchain](https://www.rust-lang.org/tools/install)
1818
- [x] [Internet Computer SDK](https://internetcomputer.org/docs/building-apps/getting-started/install)
19-
- [x] [Local installation of Bitcoin](https://internetcomputer.org/docs/building-apps/chain-fusion/bitcoin/using-btc/local-development)
20-
- [x] On macOS, an `llvm` version that supports the `wasm32-unknown-unknown` target is required. This is because the `bitcoin` library relies on `secp256k1-sys`, 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`.
19+
- [x] [Local Bitcoin testnet (regtest)](https://internetcomputer.org/docs/build-on-btc/btc-dev-env#create-a-local-bitcoin-testnet-regtest-with-bitcoind)
20+
- [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`.
2121

22-
## Step 1: Building and deploying the smart contract
22+
## Building and deploying the smart contract
2323

24-
### Clone the examples repo
24+
### 1. Clone the examples repo
2525

2626
```bash
2727
git clone https://github.com/dfinity/examples
2828
cd examples/rust/basic_bitcoin
2929
```
3030

31-
### Start the ICP local development environment
31+
### 2. Start the ICP execution environment
3232

3333
```bash
3434
dfx start --clean --background
3535
```
3636

37-
### Start the local Bitcoin testnet (regtest)
37+
### 3. Start the Bitcoin testnet (regtest)
3838

3939
In a separate terminal window, run the following:
4040

4141
```bash
4242
bitcoind -conf=$(pwd)/bitcoin.conf -datadir=$(pwd)/bitcoin_data --port=18444
4343
```
4444

45-
### Deploy the smart contract
45+
### 4. Deploy the smart contract
4646

4747
```bash
4848
dfx deploy basic_bitcoin --argument '(variant { regtest })'
@@ -61,9 +61,9 @@ Your smart contract is live and ready to use! You can interact with it using eit
6161
>
6262
> Access the Candid UI of the example: https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=vvha6-7qaaa-aaaap-ahodq-cai
6363
64-
## 2. Supported Bitcoin address types
64+
## Generating Bitcoin addresses
6565

66-
This example demonstrates how to generate and use the following address types:
66+
The example demonstrates how to generate and use the following address types:
6767

6868
1. **P2PKH (Legacy)** using ECDSA and `sign_with_ecdsa`
6969
2. **P2WPKH (SegWit v0)** using ECDSA and `sign_with_ecdsa`
@@ -77,15 +77,15 @@ dfx canister call basic_bitcoin get_p2pkh_address
7777
# or get_p2wpkh_address, get_p2tr_key_path_only_address, get_p2tr_script_path_enabled_address
7878
```
7979

80-
## 3. Receiving bitcoin
80+
## Receiving Bitcoin
8181

8282
Use the `bitcoin-cli` to mine a Bitcoin block and send the block reward in the form of local testnet BTC to one of the smart contract addresses.
8383

8484
```bash
8585
bitcoin-cli -conf=$(pwd)/bitcoin.conf generatetoaddress 1 <bitcoin_address>
8686
```
8787

88-
## 4. Checking balance
88+
## Checking balance
8989

9090
Check the balance of any Bitcoin address:
9191

@@ -95,7 +95,7 @@ dfx canister call basic_bitcoin get_balance '("<bitcoin_address>")'
9595

9696
This uses `bitcoin_get_balance` and works for any supported address type. Requires at least one confirmation to be reflected.
9797

98-
## 5. Sending bitcoin
98+
## Sending Bitcoin
9999

100100
You can send BTC using the following endpoints:
101101

@@ -123,15 +123,15 @@ dfx canister call basic_bitcoin send_from_p2pkh_address '(record {
123123
```
124124

125125
> [!IMPORTANT]
126-
> Newly created bitcoin, like those you created with the above `bitcoin-cli` command cannot be spent until 10 additional blocks have been added to the chain. To make your bitcoin spendable, create 10 additional blocks. Choose one of the smart contract addresses as receiver of the block reward or use any valid bitcoin dummy address.
126+
> Newly mined bitcoin, like those you created with the above `bitcoin-cli` command cannot be spent until 100 additional blocks have been added to the chain. To make your bitcoin spendable, create 100 additional blocks. Choose one of the smart contract addresses as receiver of the block reward or use any valid bitcoin dummy address.
127127
>
128128
> ```bash
129-
> bitcoin-cli -conf=$(pwd)/bitcoin.conf generatetoaddress 10 <bitcoin_address>
129+
> bitcoin-cli -conf=$(pwd)/bitcoin.conf generatetoaddress 100 <bitcoin_address>
130130
> ```
131131
132-
The function returns the transaction ID, which you can track on [mempool.space testnet4](https://mempool.space/testnet4/).
132+
The function returns the transaction ID. When interacting with the contract deployed on IC mainnet, you can track testnet transactions on [mempool.space](https://mempool.space/testnet4/).
133133
134-
## 6. Retrieving block headers
134+
## Retrieving block headers
135135
136136
You can query historical block headers:
137137
@@ -148,20 +148,7 @@ This calls `bitcoin_get_block_headers`, useful for validating blockchains or lig
148148
- Keys are derived using structured derivation paths according to BIP-32.
149149
- Key caching is used to avoid repeated calls to `get_ecdsa_public_key` and `get_schnorr_public_key`.
150150
- Transactions are assembled and signed manually, ensuring maximum flexibility in construction and fee estimation.
151-
152-
## Conclusion
153-
154-
In this tutorial, you were able to:
155-
156-
- Deploy a smart contract locally that can receive & send bitcoin.
157-
- Connect the smart contract to the local Bitcoin testnet.
158-
- Send the smart contract some local testnet BTC.
159-
- Check the local testnet BTC balance of the smart contract.
160-
- Use the smart contract to send local testnet BTC to another local testnet BTC address.
161-
162-
The steps to develop Bitcoin dapps locally are extensively documented in [this tutorial](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
163-
164-
Note that for _testing_ on mainnet, the [chain-key testing canister](https://github.com/dfinity/chainkey-testing-canister) can be used to save on costs for calling the threshold signing APIs for signing the BTC transactions.
151+
- When _testing_ on mainnet, the [chain-key testing canister](https://github.com/dfinity/chainkey-testing-canister) can be used to save on costs for calling the threshold signing APIs for signing the BTC transactions.
165152

166153
## Security considerations and best practices
167154

@@ -174,4 +161,4 @@ For example, the following aspects are particularly relevant for this app:
174161

175162
---
176163

177-
_Last updated: May 2025_
164+
_Last updated: June 2025_

rust/basic_bitcoin/dfx.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
"defaults": {
2121
"bitcoin": {
2222
"enabled": true,
23-
"nodes": ["127.0.0.1:18444"],
24-
"log_level": "error"
25-
},
26-
"build": {
27-
"packtool": "",
28-
"args": ""
23+
"nodes": ["127.0.0.1:18444"]
2924
}
3025
},
3126
"networks": {

0 commit comments

Comments
 (0)