当前位置:网站首页>Dfinity (ICP) deployment and development-2

Dfinity (ICP) deployment and development-2

2022-06-13 07:58:00 Boiled soybeans in brine

Dfinity Deployment and development

Download and install

at present ,DFINITY Canister SDK Only when equipped with macOS or Linux Running on a computer with an operating system !

Prerequisite installation nodejs

Directly from the terminal on the local computer shell Download the latest version of DFINITY Canister Software development kit (SDK)

sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"

This command prompts you to install... On your local computer DFINITY Execute the command line interface (CLI) And its dependencies

type y And press Return continue installation

verification SDK Ready to use

dfx By running the following command , Check that you have installed DFINITY Execute the command line interface (CLI) And the executable file is in your PATH Available in the

dfx --version
# The command shows dfx The version information of the command line executable , Similar to :
dfx 0.7.2

dfx --help
# The command shows dfx Usage information of the parent command and its child commands 

Create application examples

adopt dfx Command to create a file named hello Project

dfx new hello

The dfx new hello Command to create a new... For your project hello Project directory 、 Template file and a Git The repository

Start the local network

Use the project directory as the... In both terminals Current working directory

Run the start command :

dfx start

Keep the terminal running , Open the second terminal window

register 、 Build and deploy applications

node You have to , Ensure that the module is available in your project directory by running the following command

npm install

Register by running the following command 、 Build and deploy your first application

dfx deploy

dfx deploy Output display information about the operation it performs . for example , This step registers two network specific identifiers —— One for the hello The main program , One for the hello_assets Front end user interface —— And installation information similar to the following :

Creating the "default" identity.
  - generating new key at /Users/pubs/.config/dfx/identity/default/identity.pem
Created the "default" identity.
Creating a wallet canister on the local network.
The wallet canister on the "local" network for user "pubs_user_id" is "rwlgt-iiaaa-aaaaa-aaaaa-cai"
Deploying all canisters.
Creating canisters...
Creating canister "hello"...
"hello" canister created with canister id: "rrkah-fqaaa-aaaaa-aaaaq-cai"
Creating canister "hello_assets"...
"hello_assets" canister created with canister id: "ryjl3-tyaaa-aaaaa-aaaba-cai"
Building canisters...
Building frontend...
Installing canisters...
Creating UI canister on the local network.
The UI canister on the "local" network is "r7inp-6aaaa-aaaaa-aaabq-cai"
Installing code for canister hello, with canister_id rrkah-fqaaa-aaaaa-aaaaq-cai
Installing code for canister hello_assets, with canister_id ryjl3-tyaaa-aaaaa-aaaba-cai
Authorizing our identity (pubs_user_id) to the asset canister...
Uploading assets to asset canister...
  /index.html 1/1 (472 bytes)
  /index.html (gzip) 1/1 (314 bytes)
  /index.js 1/1 (260229 bytes)
  /index.js (gzip) 1/1 (87771 bytes)
  /main.css 1/1 (484 bytes)
  /main.css (gzip) 1/1 (263 bytes)
  /sample-asset.txt 1/1 (24 bytes)
  /logo.png 1/1 (25397 bytes)
  /index.js.map 1/1 (842559 bytes)
  /index.js.map (gzip) 1/1 (228432 bytes)
  /index.js.LICENSE.txt 1/1 (499 bytes)
  /index.js.LICENSE.txt (gzip) 1/1 (285 bytes)
Deployed canisters.

When first deployed ,dfx Will create a default Identity and one by your default Identity controlled local loop wallet . The cycle wallet is a special type of container , Allows you to transfer cycles to other containers .

To deploy this sample application locally , You don't need to know about the default developer identity 、 Use the cycle wallet or manage any information about the cycle . We will cover these topics later , But now , Note that these themes are automatically created for you

Call... By running the following command hello Containers and predefined greet function

dfx canister call hello greet everyone
  • The dfx canister call The command requires you to specify the container name and the method or function to call .
  • hello Specifies the Containers The name of .
  • greet Specifies the... To be called in the container function The name of hello.
  • everyone It's to pass on to greet The text data type parameter of the function .

Verify command display greet The return value of the function

("Hello, everyone!")

Stop the network

Stop local Internet computer network , So that it will not continue to run in the background

To stop the local network :

  1. In the terminal that displays the network operation , Press Control-C Interruptible local network processes .

  2. Stop the local... Running on the local computer by running the following command Internet computer network :

    dfx stop
    
原网站

版权声明
本文为[Boiled soybeans in brine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270545188257.html