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
Projects deployed through ICP Ninja are temporary; they will only be live for 20 minutes before they are removed. The command-line tool `dfx` can be used to continue building your ICP Ninja project locally and deploy it to the mainnet.
4
+
5
+
To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps.
6
+
7
+
### 1. Install developer tools.
8
+
9
+
You can install the developer tools natively or use Dev Containers.
10
+
11
+
#### Option 1: Natively install developer tools
12
+
13
+
> Installing `dfx` natively is currently only supported on macOS and Linux systems. On Windows, it is recommended to use the Dev Containers option.
14
+
15
+
1. Install `dfx` with the following command:
16
+
17
+
```
18
+
19
+
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
20
+
21
+
```
22
+
23
+
> On Apple Silicon (e.g., Apple M1 chip), make sure you have Rosetta installed (`softwareupdate --install-rosetta`).
- Install the Motoko package manager [Mops](https://docs.mops.one/quick-start#2-install-mops-cli): `npm i -g ic-mops`
36
+
37
+
Lastly, navigate into your project's directory that you downloaded from ICP Ninja.
38
+
39
+
#### Option 2: Dev Containers
40
+
41
+
Continue building your projects locally by installing the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code and [Docker](https://docs.docker.com/engine/install/).
42
+
43
+
Make sure Docker is running, then navigate into your project's directory that you downloaded from ICP Ninja and start the Dev Container by selecting `Dev-Containers: Reopen in Container` in VS Code's command palette (F1 or Ctrl/Cmd+Shift+P).
44
+
45
+
> Note that local development ports (e.g. the ports used by `dfx` or `vite`) are forwarded from the Dev Container to your local machine. In the VS code terminal, use Ctrl/Cmd+Click on the displayed local URLs to open them in your browser. To view the current port mappings, click the "Ports" tab in the VS Code terminal window.
46
+
47
+
### 2. Start the local development environment.
48
+
49
+
```
50
+
dfx start --background
51
+
```
52
+
53
+
### 3. Create a local developer identity.
54
+
55
+
To manage your project's canisters, it is recommended that you create a local [developer identity](https://internetcomputer.org/docs/building-apps/getting-started/identities) rather than use the `dfx` default identity that is not stored securely.
56
+
57
+
To create a new identity, run the commands:
58
+
59
+
```
60
+
61
+
dfx identity new IDENTITY_NAME
62
+
63
+
dfx identity use IDENTITY_NAME
64
+
65
+
```
66
+
67
+
Replace `IDENTITY_NAME` with your preferred identity name. The first command `dfx start --background` starts the local `dfx` processes, then `dfx identity new` will create a new identity and return your identity's seed phase. Be sure to save this in a safe, secure location.
68
+
69
+
The third command `dfx identity use` will tell `dfx` to use your new identity as the active identity. Any canister smart contracts created after running `dfx identity use` will be owned and controlled by the active identity.
70
+
71
+
Your identity will have a principal ID associated with it. Principal IDs are used to identify different entities on ICP, such as users and canisters.
72
+
73
+
[Learn more about ICP developer identities](https://internetcomputer.org/docs/building-apps/getting-started/identities).
74
+
75
+
### 4. Deploy the project locally.
76
+
77
+
Deploy your project to your local developer environment with:
78
+
79
+
```
80
+
npm install
81
+
dfx deploy
82
+
83
+
```
84
+
85
+
Your project will be hosted on your local machine. The local canister URLs for your project will be shown in the terminal window as output of the `dfx deploy` command. You can open these URLs in your web browser to view the local instance of your project.
86
+
87
+
### 5. Obtain cycles.
88
+
89
+
To deploy your project to the mainnet for long-term public accessibility, first you will need [cycles](https://internetcomputer.org/docs/building-apps/getting-started/tokens-and-cycles). Cycles are used to pay for the resources your project uses on the mainnet, such as storage and compute.
90
+
91
+
> This cost model is known as ICP's [reverse gas model](https://internetcomputer.org/docs/building-apps/essentials/gas-cost), where developers pay for their project's gas fees rather than users pay for their own gas fees. This model provides an enhanced end user experience since they do not need to hold tokens or sign transactions when using a dapp deployed on ICP.
92
+
93
+
> Learn how much a project may cost by using the [pricing calculator](https://internetcomputer.org/docs/building-apps/essentials/cost-estimations-and-examples).
94
+
95
+
Cycles can be obtained through [converting ICP tokens into cycles using `dfx`](https://internetcomputer.org/docs/building-apps/developer-tools/dfx/dfx-cycles#dfx-cycles-convert).
96
+
97
+
### 6. Deploy to the mainnet.
98
+
99
+
Once you have cycles, run the command:
100
+
101
+
```
102
+
103
+
dfx deploy --network ic
104
+
105
+
```
106
+
107
+
After your project has been deployed to the mainnet, it will continuously require cycles to pay for the resources it uses. You will need to [top up](https://internetcomputer.org/docs/building-apps/canister-management/topping-up) your project's canisters or set up automatic cycles management through a service such as [CycleOps](https://cycleops.dev/).
108
+
109
+
> If your project's canisters run out of cycles, they will be removed from the network.
110
+
111
+
## Additional examples
112
+
113
+
Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples).
Copy file name to clipboardExpand all lines: motoko/basic_bitcoin/README.md
+16-83Lines changed: 16 additions & 83 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,72 +12,31 @@ of the Internet Computer.
12
12
13
13
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).
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
24
22
25
-
Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands:
23
+
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)
26
24
25
+
### 3. Navigate into the project's directory.
27
26
28
-
```bash
29
-
cd examples/motoko/basic_bitcoin
30
-
dfx start --background
31
-
```
32
-
33
-
### Install MOPS
34
-
35
-
[Install](https://docs.mops.one/quick-start#2-install-mops-cli) the MOPS package
36
-
manager, e.g., by running
27
+
### 4. Deploy the project to your local environment:
37
28
38
-
```bash
39
-
curl -fsSL cli.mops.one/install.sh | sh
40
29
```
41
-
42
-
### Acquire cycles to deploy
43
-
44
-
Deploying to the Internet Computer requires [cycles](https://internetcomputer.org/docs/current/developer-docs/getting-started/tokens-and-cycles) (the equivalent of "gas" on other blockchains).
45
-
46
-
### Deploy the smart contract to the Internet Computer
-`dfx deploy` tells the command line interface to `deploy` the smart contract
54
-
-`--network=ic` tells the command line to deploy the smart contract to the mainnet ICP blockchain
55
-
-`--argument '(variant { Testnet })'` passes the argument `Testnet` to initialize the smart contract, telling it to connect to the Bitcoin testnet
56
-
57
-
**We're initializing the canister with `variant { testnet }` so that the
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
61
-
testnet.**
62
-
63
-
If successful, you should see an output that looks like this:
Your canister is live and ready to use! You can interact with it using either the command line or the Candid UI, which is the link you see in the output above.
35
+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
76
36
77
-
In the output above, to see the Candid Web UI for your bitcoin canister, you would use the URL `https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=<YOUR-CANISTER-ID>`. Candid
78
-
Web UI will contain all methods implemented by the canister.
37
+
## Using the basic_bitcoin example
79
38
80
-
## Step 2: Generating a Bitcoin address
39
+
###Step 1: Generating a Bitcoin address
81
40
82
41
Bitcoin has different types of addresses (e.g. P2PKH, P2SH, P2TR). You may want
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.
146
105
147
-
## Step 5: Sending bitcoin
106
+
###Step 4: Sending bitcoin
148
107
149
108
You can send bitcoin using the `send_from_${type}` endpoint on your canister, where
150
109
`${type}` is one of
@@ -177,7 +136,7 @@ it sent to the network. You can track the status of this transaction using a
177
136
transaction has at least one confirmation, you should be able to see it
178
137
reflected in your current balance.
179
138
180
-
## Step 6: Retrieving block headers
139
+
###Step 5: Retrieving block headers
181
140
182
141
You can also get a range of Bitcoin block headers by using the `get_block_headers`
183
142
endpoint on your canister.
@@ -193,29 +152,3 @@ or replace `0` and `11` with your desired start and end height respectively:
* Deploy a canister smart contract on the ICP blockchain that can receive & send Bitcoin.
202
-
* Acquire cycles to deploy the canister to the ICP mainnet.
203
-
* Connect the canister to the Bitcoin testnet.
204
-
* Send the canister some testnet BTC.
205
-
* Check the testnet BTC balance of the canister.
206
-
* Use the canister to send testnet BTC to another testnet BTC address.
207
-
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).
209
-
210
-
Note that for *testing* on mainnet, the [chain-key testing
211
-
canister](https://github.com/dfinity/chainkey-testing-canister) can be used to
212
-
save on costs for calling the threshold signing APIs for signing the BTC
213
-
transactions.
214
-
215
-
## Security considerations and best practices
216
-
217
-
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.
218
-
219
-
For example, the following aspects are particularly relevant for this app:
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.
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.
0 commit comments