【准备工作】
创建一个名为hello的新项目:
dfx new hello
/The dfx new xxx command creates a new hello project directly, template files, and a new hello Git repository for your project./
转到项目目录:
cd hello
【在本地部署/Start(local)】
新建一个终端,转到项目目录,然后通过运行以下命令,在第二个终端中的本地计算机上启动internet计算机网络:
dfx start
根据您的平台和本地安全设置,您可能会看到显示警告。如果系统提示您允许或拒绝传入的网络连接,请单击允许。
(也可以不用新建一个终端,直接用
dfx start --background
即可启动IC网络服务)
其余操作在第一个终端中进行。
【注册,构建和部署应用程序】
1.确保仍在项目的根目录中。
2.Ensure that node modules are available in your project directory, if needed, by running the following command:
npm install
之后,若版本过旧,可能会让您更新,默认的语句提示为:
npm install -g npm
但,运行此命令后会报错(EACCES:permission denied……)
根据我孱弱的经验和知识,在前面加上sudo并在运行此命令之后输入密码就可以了~即:
sudo npm install -g npm
3.Register, build, and deploy your first application by running the following command:
dfx deploy
The dfx deploy command output displays information about the operations it performs. For example, this step registers two network-specific identifiers—one for the hello main program and 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.
Deploying all canisters.
Creating canisters...
Creating canister "hello"...
Creating the canister using the wallet canister...
Creating a wallet canister on the local network.
The wallet canister on the "local" network for user "default" is "rwlgt-iiaaa-aaaaa-aaaaa-cai"
"hello" canister created with canister id: "rrkah-fqaaa-aaaaa-aaaaq-cai"
Creating canister "hello_assets"...
Creating the canister using the wallet canister...
"hello_assets" canister created with canister id: "ryjl3-tyaaa-aaaaa-aaaba-cai"
Building canisters...
Building frontend...
Installing canisters...
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 (default) to the asset canister...
Uploading assets to asset canister...
Deployed canisters.」
4.Call the hello canister and the predefined greet function by running the following command:
dfx canister call hello greet everyone
This example uses the dfx canister call command to pass "everyone" as an argument to the greet function.
5.Verify the command displays the return value of the greet function.
For example:
("Hello, everyone!")
【Test the application front-end】
Open a browser.
Navigate to the default address and port number 127.0.0.1:8000, then append /?canisterId= and the hello_assets identifier to the URL.
For example, the full URL should look similar to the following:
http://127.0.0.1:8000/?canisterId=rrkah-fqaaa-aaaaa-aaaaq-cai
Navigating to this URL displays the prompt pop-up window. For example:
Type a greeting, then click OK to return the greeting.
3.For example:
4. Click OK to close the alert pop-up window.
【Stop the local network】
After testing the application in the browser, you can stop the local Internet Computer network so that it doesn’t continue running in the background.
To stop the local network:
1.In the terminal that displays network operations, press Control-C to interrupt the local network process.
2.Stop the local Internet Computer network running on your local computer by running the following command:
dfx stop
【Start(Network)】
【检查与网络的连接】
1.先检查您是否位于项目的根目录中。
2.通过运行以下网络别名命令,检查Internet计算机网络ic的当前状态以及您连接到它的能力:
dfx ping ic
如果您在自己的计算机上修改了Internet Computer网络的网络别名 dfx.json文件,则替换ic网络别名,以及在此命令和后续命令中使用的别名。
【注册,构建和部署应用程序】
1.先检查您是否位于项目的根目录中。
2.确保node的状态,可以通过运行以下命令在项目的目录中使用模块:
npm install
3.通过运行以下命令注册,构建和部署您的应用程序:
dfx deploy --network=ic
之后会得到wallet canister的id、”hello”canister的id、”hello_assets”的id.
4.(可略)可用以下命令来调用预定义的greet函数来call “hello”canister:
dfx canister --network=ic call hello greet everyone
5.可用以下命令得到wallet canister identifier (id) :
dfx identity --network=ic get-wallet
6.可用以下命令查询wallet balance
dfx canister --network=ic call 钱包id wallet_balance
之后,会得到当前剩余的cycles数。
【测试应用程序前端】
1.打开浏览器
2.使用包含以下内容的URL导航到应用程序的前端:hello_assets标识符和
.ic0.app后缀。
例如,完整的URL应该类似以下内容:
https://embed-daaaa-aaaab-aachen-can.ic0.app/
Comments 4 条评论
博客作者 红烧鱼
来ました,応援します!
博客作者 QiuYeDx
@红烧鱼 ありがとう妹~
博客作者 Johnson
It’s so nice!
博客作者 zoritoler imol
F*ckin’ awesome issues here. I am very satisfied to peer your post. Thanks a lot and i’m looking forward to contact you. Will you please drop me a mail?