@@ -15,12 +15,9 @@ For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin inte
15
15
## Prerequisites
16
16
17
17
- [x] Install the [ IC
18
- SDK] ( https://internetcomputer.org/docs/current/developer-docs/getting-started/install ) . For local testing, ` dfx >= 0.22.0 ` is required.
18
+ SDK] ( https://internetcomputer.org/docs/current/developer-docs/getting-started/install ) .
19
19
- [x] Clone the example dapp project: ` git clone https://github.com/dfinity/examples `
20
20
21
- > [ !WARNING]
22
- > This example is designed to be deployed on the mainnet. It will return errors when deployed locally; these errors are expected.
23
-
24
21
Begin by opening a terminal window.
25
22
26
23
## Step 1: Setup the project environment
@@ -89,58 +86,40 @@ to check [this
89
86
article] ( https://bitcoinmagazine.com/technical/bitcoin-address-types-compared-p2pkh-p2sh-p2wpkh-and-more )
90
87
if you are interested in a high-level comparison of different address types.
91
88
These addresses can be generated from an ECDSA public key or a Schnorr
92
- ([ BIP340] ( https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki ) )
93
- public key. The example code showcases how your canister can generate and spend
94
- from three types of addresses:
89
+ ([ BIP340] ( https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki ) ,
90
+ [ BIP341] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki ) ) public
91
+ key. The example code showcases how your canister can generate and spend from
92
+ three types of addresses:
95
93
1 . A [ P2PKH address] ( https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash )
96
94
using the
97
95
[ ecdsa_public_key] ( https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-ecdsa_public_key )
98
96
API.
99
97
2 . A [ P2TR
100
98
address] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki )
101
- where the funds can be spent using the raw (untweaked) internal key
102
- (so-called P2TR key path spend, but untweaked). The advantage of this
103
- approach compared to P2TR script spends is its significantly smaller fee per
104
- transaction because checking the transaction signature is analogous to P2PK
105
- but uses Schnorr instead of ECDSA. The limitation of untweaked P2TR addresses
106
- is that they cannot be used with scripts. IMPORTANT: Note that
107
- [ BIP341] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-23 )
108
- advises against using taproot addresses that can be spent with an untweaked
109
- key. This precaution is to prevent attacks that can occur when creating
110
- taproot multisigner addresses using specific multisignature schemes. However,
111
- the Schnorr API of the internet computer does not support Schnorr
112
- multisignatures.
99
+ where the funds can be spent using the internal key only ([ P2TR key path
100
+ spend with unspendable script
101
+ tree] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-23 ) ).
113
102
3 . A [ P2TR
114
103
address] ( https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki )
115
- where the funds can be spent using the provided public key with the script
116
- path, where the Merkelized Alternative Script Tree (MAST) consists of a
117
- single script allowing to spend funds by exactly one key.
118
-
119
- Note that P2TR * key path* spending with a tweaked key is currently not available
120
- on the IC because the threshold Schnorr signing interface does not allow
121
- applying BIP341 tweaks to the private key. In contrast, the
122
- tweaked public key is used to spend in the script path, which is availble on the
123
- IC. For a technical comparison of different ways of how single-signer P2TR
124
- addresses can be constructed and used, you may want to take a look at [ this
125
- post] ( https://bitcoin.stackexchange.com/a/111100 ) by Pieter Wuille.
104
+ where the funds can be spent using either 1) the internal key or 2) the
105
+ provided public key with the script path, where the Merkelized Alternative
106
+ Script Tree (MAST) consists of a single script allowing to spend funds by
107
+ exactly one key.
126
108
127
109
On the Candid UI of your canister, click the "Call" button under
128
110
` get_${type}_address ` to generate a ` ${type} ` Bitcoin address, where ` ${type} `
129
- is one of ` [p2pkh, p2tr_raw_key_spend, p2tr_script_spend] ` .
111
+ is one of ` [p2pkh, p2tr_key_only, p2tr] ` (corresponding to the three types of
112
+ addresses described above, in the same order).
130
113
131
114
Or, if you prefer the command line:
132
115
133
116
``` bash
134
117
dfx canister --network=ic call basic_bitcoin get_${type} _address
135
118
```
136
119
137
- * The Bitcoin address you see will be different from the one above because the
138
- ECDSA public key your canister retrieves is unique.
139
-
140
120
* We are generating a Bitcoin testnet address, which can only be
141
121
used for sending/receiving Bitcoin on the Bitcoin testnet.
142
122
143
-
144
123
## Step 3: Receiving bitcoin
145
124
146
125
Now that the canister is deployed and you have a Bitcoin address, it's time to receive
@@ -150,7 +129,6 @@ to receive some bitcoin.
150
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
151
130
because the ECDSA/Schnorr public key your canister retrieves is unique.
152
131
153
-
154
132
Once the transaction has at least one confirmation, which can take a few minutes,
155
133
you'll be able to see it in your canister's balance.
156
134
@@ -171,15 +149,16 @@ Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](ht
171
149
## Step 5: Sending bitcoin
172
150
173
151
You can send bitcoin using the ` send_from_${type} ` endpoint on your canister, where
174
- ` ${type} ` is on of ` [p2pkh, p2tr_raw_key_spend, p2tr_script_spend] ` .
152
+ ` ${type} ` is one of
153
+ ` [p2pkh_address, p2tr_key_only_address, p2tr_address_key_path, p2tr_address_script_path] ` .
175
154
176
155
In the Candid UI, add a destination address and an amount to send. In the example
177
156
below, we're sending 4'321 Satoshi (0.00004321 BTC) back to the testnet faucet.
178
157
179
158
Via the command line, the same call would look like this:
180
159
181
160
``` bash
182
- dfx canister --network=ic call basic_bitcoin send_from_p2pkh ' (record { destination_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"; amount_in_satoshi = 4321; })'
161
+ dfx canister --network=ic call basic_bitcoin send_from_p2pkh_address ' (record { destination_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"; amount_in_satoshi = 4321; })'
183
162
```
184
163
185
164
The ` send_from_${type} ` endpoint can send bitcoin by:
0 commit comments