Skip to content

Commit 14c1baf

Browse files
Merge pull request #1107 from dfinity/tl/testnet4_update
chore: Update the basic_bitcoin README files due to the move to testnet4
2 parents f7e90c5 + b8b890a commit 14c1baf

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

.github/workflows/rust-basic-bitcoin-example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
run: |
2727
dfx start --background
2828
pushd rust/basic_bitcoin
29+
rustup show active-toolchain || rustup toolchain install
2930
make deploy
3031
popd
3132
rust-basic-bitcoin-linux:

motoko/basic_bitcoin/README.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This tutorial will walk you through how to deploy a sample [canister smart contr
77
This example internally leverages the [ECDSA
88
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-ecdsa_public_key),
99
[Schnorr API](https://internetcomputer.org/docs/current/references/ic-interface-spec#ic-sign_with_schnorr), and [Bitcoin
10-
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin-api)
10+
API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md)
1111
of the Internet Computer.
1212

1313
For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin integration documentation](https://internetcomputer.org/docs/current/developer-docs/multi-chain/bitcoin/overview).
@@ -55,13 +55,11 @@ dfx deploy --network=ic basic_bitcoin --argument '(variant { testnet })'
5555
- `--argument '(variant { Testnet })'` passes the argument `Testnet` to initialize the smart contract, telling it to connect to the Bitcoin testnet
5656

5757
**We're initializing the canister with `variant { testnet }` so that the
58-
canister connects to the [Bitcoin testnet](https://en.bitcoin.it/wiki/Testnet).
59-
To be specific, this connects to `Testnet3`, which is the current Bitcoin test
60-
network used by the Bitcoin community. This means that the addresses generated
61-
in the smart contract can only be used to receive or send funds only on Bitcoin
58+
canister connects to the Bitcoin testnet.
59+
To be specific, the canister interacts with [testnet4](https://mempool.space/testnet4), which is the latest Bitcoin test network used by the Bitcoin community. This means that the addresses generated
60+
in the smart contract can only be used to receive or send funds on this Bitcoin
6261
testnet.**
6362

64-
6563
If successful, you should see an output that looks like this:
6664

6765
```bash
@@ -124,12 +122,12 @@ used for sending/receiving Bitcoin on the Bitcoin testnet.
124122

125123
Now that the canister is deployed and you have a Bitcoin address, it's time to receive
126124
some testnet bitcoin. You can use one of the Bitcoin faucets, such as [coinfaucet.eu](https://coinfaucet.eu),
127-
to receive some bitcoin.
125+
to receive some bitcoin. **Make sure to choose Bitcoin testnet4!**
128126

129-
Enter your address and click on "Send testnet bitcoins". In the example below we will use Bitcoin address `n31eU1K11m1r58aJMgTyxGonu7wSMoUYe7`, but you will use your address. The Bitcoin address you see will be different from the one above
127+
Enter your address and click on "Get bitcoins!". In the example below we will use Bitcoin address `n31eU1K11m1r58aJMgTyxGonu7wSMoUYe7`, but you will use your address. The Bitcoin address you see will be different from the one above
130128
because the ECDSA/Schnorr public key your canister retrieves is unique.
131129

132-
Once the transaction has at least one confirmation, which can take a few minutes,
130+
Once the transaction has at least one confirmation, which takes ten minutes on average,
133131
you'll be able to see it in your canister's balance.
134132

135133
## Step 4: Checking your bitcoin balance
@@ -144,7 +142,7 @@ Alternatively, make the call using the command line. Be sure to replace `mheyfRs
144142
dfx canister --network=ic call basic_bitcoin get_balance '("mheyfRsAQ1XrjtzjfU1cCH2B6G1KmNarNL")'
145143
```
146144

147-
Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_balance) API.
145+
Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_balance) API.
148146

149147
## Step 5: Sending bitcoin
150148

@@ -163,22 +161,39 @@ dfx canister --network=ic call basic_bitcoin send_from_p2pkh_address '(record {
163161

164162
The `send_from_${type}` endpoint can send bitcoin by:
165163

166-
1. Getting the percentiles of the most recent fees on the Bitcoin network using the [bitcoin_get_current_fee_percentiles API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-bitcoin_get_current_fee_percentiles).
167-
2. Fetching your unspent transaction outputs (UTXOs), using the [bitcoin_get_utxos API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-bitcoin_get_utxos).
164+
1. Getting the percentiles of the most recent fees on the Bitcoin network using the [bitcoin_get_current_fee_percentiles API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_current_fee_percentiles).
165+
2. Fetching your unspent transaction outputs (UTXOs), using the [bitcoin_get_utxos API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_utxos).
168166
3. Building a transaction, using some of the UTXOs from step 2 as input and the destination address and amount to send as output.
169167
The fee percentiles obtained from step 1 are used to set an appropriate fee.
170168
4. Signing the inputs of the transaction using the
171169
[sign_with_ecdsa
172170
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-sign_with_ecdsa)/\
173171
[sign_with_schnorr](https://org5p-7iaaa-aaaak-qckna-cai.icp0.io/docs#ic-sign_with_schnorr).
174-
5. Sending the signed transaction to the Bitcoin network using the [bitcoin_send_transaction API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-bitcoin_send_transaction).
172+
5. Sending the signed transaction to the Bitcoin network using the [bitcoin_send_transaction API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_send_transaction).
175173

176174
This canister's `send_from_${type}` endpoint returns the ID of the transaction
177175
it sent to the network. You can track the status of this transaction using a
178176
[block explorer](https://en.bitcoin.it/wiki/Block_chain_browser). Once the
179177
transaction has at least one confirmation, you should be able to see it
180178
reflected in your current balance.
181179

180+
## Step 6: Retrieving block headers
181+
182+
You can also get a range of Bitcoin block headers by using the `get_block_headers`
183+
endpoint on your canister.
184+
185+
In the Candid UI, write the desired start height and optionally end height, and click on "Call":
186+
187+
Alternatively, make the call using the command line. Be sure to replace `10` with your desired start height:
188+
189+
```bash
190+
dfx canister --network=ic call basic_bitcoin get_block_headers "(10: nat32)"
191+
```
192+
or replace `0` and `11` with your desired start and end height respectively:
193+
```bash
194+
dfx canister --network=ic call basic_bitcoin get_block_headers "(0: nat32, 11: nat32)"
195+
```
196+
182197
## Conclusion
183198

184199
In this tutorial, you were able to:
@@ -190,10 +205,7 @@ In this tutorial, you were able to:
190205
* Check the testnet BTC balance of the canister.
191206
* Use the canister to send testnet BTC to another testnet BTC address.
192207

193-
This example is extensively documented in the following tutorials:
194-
195-
* [Deploying your first Bitcoin dapp](https://internetcomputer.org/docs/current/samples/deploying-your-first-bitcoin-dapp).
196-
* [Developing Bitcoin dapps locally](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
208+
The steps to develop Bitcoin dapps locally are extensively documented in [this tutorial](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
197209

198210
Note that for *testing* on mainnet, the [chain-key testing
199211
canister](https://github.com/dfinity/chainkey-testing-canister) can be used to
@@ -206,6 +218,4 @@ If you base your application on this example, we recommend you familiarize yours
206218

207219
For example, the following aspects are particularly relevant for this app:
208220
* [Certify query responses if they are relevant for security](https://internetcomputer.org/docs/current/references/security/general-security-best-practices#certify-query-responses-if-they-are-relevant-for-security), since the app e.g. offers a method to read balances.
209-
* [Use a decentralized governance system like SNS to make a canister have a decentralized controller](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview)
210-
211-
This implementation has only been tested locally with regtest.
221+
* [Use a decentralized governance system like SNS to make a canister have a decentralized controller](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview) since decentralized control may be essential for canisters holding bitcoins on behalf of users.

rust/basic_bitcoin/README.md

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-
99
[Schnorr
1010
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr),
1111
and [Bitcoin
12-
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin-api)
12+
API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md)
1313
of the Internet Computer.
1414

1515
For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin integration documentation](https://wiki.internetcomputer.org/wiki/Bitcoin_Integration).
@@ -25,10 +25,6 @@ For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin inte
2525

2626
## Step 1: Building and deploying sample code
2727

28-
This tutorial has the same smart contract written in
29-
[Motoko](https://internetcomputer.org/docs/current/developer-docs/backend/motoko/index.md)
30-
using ECDSA, Schnorr, and Bitcoin API.
31-
3228
You can clone and deploy either one, as they both function in the same way.
3329

3430
To clone and build the smart contract in **Rust**:
@@ -55,10 +51,9 @@ dfx deploy --network=ic basic_bitcoin --argument '(variant { testnet })'
5551
- `--argument '(variant { testnet })'` passes the argument `testnet` to initialize the smart contract, telling it to connect to the Bitcoin testnet
5652

5753
**We're initializing the canister with `variant { testnet }` so that the
58-
canister connects to the [Bitcoin testnet](https://en.bitcoin.it/wiki/Testnet).
59-
To be specific, this connects to `Testnet4`, which is the current Bitcoin test
60-
network used by the Bitcoin community. This means that the addresses generated
61-
in the smart contract can only be used to receive or send funds only on Bitcoin
54+
canister connects to the Bitcoin testnet.
55+
To be specific, the canister interacts with [testnet4](https://mempool.space/testnet4), which is the latest Bitcoin test network used by the Bitcoin community. This means that the addresses generated
56+
in the smart contract can only be used to receive or send funds on this Bitcoin
6257
testnet.**
6358

6459
If successful, you should see an output that looks like this:
@@ -124,42 +119,32 @@ Or, if you prefer the command line:
124119
## Step 3: Receiving bitcoin
125120

126121
Now that the canister is deployed and you have a Bitcoin address, it's time to receive
127-
some testnet bitcoin. You can use one of the Bitcoin faucets, such as [coinfaucet.eu](https://coinfaucet.eu),
128-
to receive some bitcoin.
122+
some testnet bitcoin. You can use one of the Bitcoin faucets, such as [coinfaucet.eu](https://coinfaucet.eu), to receive some bitcoin. **Make sure to choose Bitcoin testnet4!**
129123

130-
Enter your address and click on "Send testnet bitcoins". This example will use
131-
the Bitcoin P2PHK address `mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx`, but you will use
124+
Enter your address and click on "Get bitcoins!". This example will use
125+
the Bitcoin P2PHK address `n3eGjsKEciCW52xPJf8j18MQEdDqowtb3X`, but you will use
132126
your address. The Bitcoin address you see will be different from the one above
133127
because the ECDSA/Schnorr public key your canister retrieves is unique.
134128

135-
Once the transaction has at least one confirmation, which can take a few minutes,
129+
Once the transaction has at least one confirmation, which takes ten minutes on average,
136130
you'll be able to see it in your canister's balance.
137131

138-
The addresses that have been used for the testing of this canister on Bitcoin
139-
testnet are `mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx` (P2PKH,
140-
[transactions](https://blockstream.info/testnet/address/mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx)),
141-
`tb1pkkrwg6e9s5zf3jmftu224rc5ppax26g5yzdg03rhmqw84359xgpsv5mn2y` (P2TR raw key
142-
spend,
143-
[transactions](https://blockstream.info/testnet/address/tb1pkkrwg6e9s5zf3jmftu224rc5ppax26g5yzdg03rhmqw84359xgpsv5mn2y)),
144-
and `tb1pnm743sjkw9tq3zf9uyetgqkrx7tauthmxnsl5dtyrwnyz9r7lu8qdtcnnc` (P2TR
145-
script path spend,
146-
[transactions](https://blockstream.info/testnet/address/tb1pnm743sjkw9tq3zf9uyetgqkrx7tauthmxnsl5dtyrwnyz9r7lu8qdtcnnc)).
147-
It may be useful to click on "transactions" links if you are interested in how
148-
they are structured.
132+
The P2PKH address that has been used for the testing of this canister on Bitcoin
133+
testnet is [n3eGjsKEciCW52xPJf8j18MQEdDqowtb3X](https://mempool.space/testnet4/address/n3eGjsKEciCW52xPJf8j18MQEdDqowtb3X).
149134

150135
## Step 4: Checking your bitcoin balance
151136

152137
You can check a Bitcoin address's balance by using the `get_balance` endpoint on your canister.
153138

154139
In the Candid UI, paste in your canister's address, and click on "Call":
155140

156-
Alternatively, make the call using the command line. Be sure to replace `mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx` with your own generated address:
141+
Alternatively, make the call using the command line. Be sure to replace `n3eGjsKEciCW52xPJf8j18MQEdDqowtb3X` with your own generated address:
157142

158143
```bash
159-
dfx canister --network=ic call basic_bitcoin get_balance '("mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx")'
144+
dfx canister --network=ic call basic_bitcoin get_balance '("n3eGjsKEciCW52xPJf8j18MQEdDqowtb3X")'
160145
```
161146

162-
Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_balance) API.
147+
Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_balance) API.
163148

164149
## Step 5: Sending bitcoin
165150

@@ -178,8 +163,8 @@ dfx canister --network=ic call basic_bitcoin send_from_p2pkh_address '(record {
178163

179164
The `send_from_${type}` endpoint can send bitcoin by:
180165

181-
1. Getting the percentiles of the most recent fees on the Bitcoin network using the [bitcoin_get_current_fee_percentiles API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_current_fee_percentiles).
182-
2. Fetching your unspent transaction outputs (UTXOs), using the [bitcoin_get_utxos API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_get_utxos).
166+
1. Getting the percentiles of the most recent fees on the Bitcoin network using the [bitcoin_get_current_fee_percentiles API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_current_fee_percentiles).
167+
2. Fetching your unspent transaction outputs (UTXOs), using the [bitcoin_get_utxos API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_get_utxos).
183168
3. Building a transaction, using some of the UTXOs from step 2 as input and the destination address and amount to send as output.
184169
The fee percentiles obtained from step 1 is used to set an appropriate fee.
185170
4. Signing the inputs of the transaction using the
@@ -188,7 +173,7 @@ The `send_from_${type}` endpoint can send bitcoin by:
188173
[sign_with_schnorr](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr).
189174
5. Sending the signed transaction to the Bitcoin network using the
190175
[bitcoin_send_transaction
191-
API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-bitcoin_send_transaction).
176+
API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md#bitcoin_send_transaction).
192177

193178
This canister's `send_from_${type}` endpoint returns the ID of the transaction
194179
it sent to the network. You can track the status of this transaction using a
@@ -224,7 +209,7 @@ In this tutorial, you were able to:
224209
* Check the testnet BTC balance of the canister.
225210
* Use the canister to send testnet BTC to another testnet BTC address.
226211

227-
This example is extensively documented in the following tutorial: [Developing Bitcoin dapps locally](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
212+
The steps to develop Bitcoin dapps locally are extensively documented in [this tutorial](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
228213

229214
Note that for *testing* on mainnet, the [chain-key testing
230215
canister](https://github.com/dfinity/chainkey-testing-canister) can be used to
@@ -237,4 +222,4 @@ If you base your application on this example, we recommend you familiarize yours
237222

238223
For example, the following aspects are particularly relevant for this app:
239224
* [Certify query responses if they are relevant for security](https://internetcomputer.org/docs/current/references/security/general-security-best-practices#certify-query-responses-if-they-are-relevant-for-security), since the app e.g. offers a method to read balances.
240-
* [Use a decentralized governance system like SNS to make a canister have a decentralized controller](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview), since decentralized control may be essential for canisters holding Bitcoin on behalf of users.
225+
* [Use a decentralized governance system like SNS to make a canister have a decentralized controller](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview), since decentralized control may be essential for canisters holding bitcoins on behalf of users.

0 commit comments

Comments
 (0)