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
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).
-`--argument '(variant { Testnet })'` passes the argument `Testnet` to initialize the smart contract, telling it to connect to the Bitcoin testnet
56
56
57
57
**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
62
61
testnet.**
63
62
64
-
65
63
If successful, you should see an output that looks like this:
66
64
67
65
```bash
@@ -124,12 +122,12 @@ used for sending/receiving Bitcoin on the Bitcoin testnet.
124
122
125
123
Now that the canister is deployed and you have a Bitcoin address, it's time to receive
126
124
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!**
128
126
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
130
128
because the ECDSA/Schnorr public key your canister retrieves is unique.
131
129
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,
133
131
you'll be able to see it in your canister's balance.
134
132
135
133
## Step 4: Checking your bitcoin balance
@@ -144,7 +142,7 @@ Alternatively, make the call using the command line. Be sure to replace `mheyfRs
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.
The `send_from_${type}` endpoint can send bitcoin by:
165
163
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).
168
166
3. Building a transaction, using some of the UTXOs from step 2 as input and the destination address and amount to send as output.
169
167
The fee percentiles obtained from step 1 are used to set an appropriate fee.
170
168
4. Signing the inputs of the transaction using the
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).
175
173
176
174
This canister's `send_from_${type}` endpoint returns the ID of the transaction
177
175
it sent to the network. You can track the status of this transaction using a
178
176
[block explorer](https://en.bitcoin.it/wiki/Block_chain_browser). Once the
179
177
transaction has at least one confirmation, you should be able to see it
180
178
reflected in your current balance.
181
179
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:
The steps to develop Bitcoin dapps locally are extensively documented in [this tutorial](https://internetcomputer.org/docs/current/developer-docs/integrations/bitcoin/local-development).
197
209
198
210
Note that for *testing* on mainnet, the [chain-key testing
199
211
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
206
218
207
219
For example, the following aspects are particularly relevant for this app:
208
220
*[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.
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
25
25
26
26
## Step 1: Building and deploying sample code
27
27
28
-
This tutorial has the same smart contract written in
-`--argument '(variant { testnet })'` passes the argument `testnet` to initialize the smart contract, telling it to connect to the Bitcoin testnet
56
52
57
53
**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
62
57
testnet.**
63
58
64
59
If successful, you should see an output that looks like this:
@@ -124,42 +119,32 @@ Or, if you prefer the command line:
124
119
## Step 3: Receiving bitcoin
125
120
126
121
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!**
129
123
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
132
126
your address. The Bitcoin address you see will be different from the one above
133
127
because the ECDSA/Schnorr public key your canister retrieves is unique.
134
128
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,
136
130
you'll be able to see it in your canister's balance.
137
131
138
-
The addresses that have been used for the testing of this canister on Bitcoin
139
-
testnet are `mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx` (P2PKH,
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.
The `send_from_${type}` endpoint can send bitcoin by:
180
165
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).
183
168
3. Building a transaction, using some of the UTXOs from step 2 as input and the destination address and amount to send as output.
184
169
The fee percentiles obtained from step 1 is used to set an appropriate fee.
185
170
4. Signing the inputs of the transaction using the
@@ -188,7 +173,7 @@ The `send_from_${type}` endpoint can send bitcoin by:
This canister's `send_from_${type}` endpoint returns the ID of the transaction
194
179
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:
224
209
* Check the testnet BTC balance of the canister.
225
210
* Use the canister to send testnet BTC to another testnet BTC address.
226
211
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).
228
213
229
214
Note that for *testing* on mainnet, the [chain-key testing
230
215
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
237
222
238
223
For example, the following aspects are particularly relevant for this app:
239
224
*[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