环境
我的环境是Mac,如果是win或者Linux可以看官网的部署文档。
1.安装SDK
打开shll终端
#安装SDK
sh -ci "$(curl -fsSL https://smartcontracts.org/install.sh)"
#查看安装目录
which dfx
#把安装目录加到系统路径
export PATH=/usr/local/bin:$PATH
2.创建项目
dfx new web_demo
2.启动项目
先cd到项目根路径,然后启动项目
#启动服务
dfx start
#在后台启动服务
#dfx start --backgrouns
启动完成之后,让它一直在这个界面停留,之后打开另一个终端,开始编码。
停止服务
#停止服务
dfx stop
3.在本地部署项目
再打一个终端,cd到项目根目录,部署项目
dfx deploy
访问前端
http://ryjl3-tyaaa-aaaaa-aaaba-cai.localhost:8000
这样就算在本地部署完成。
4.在主网部署项目
ID
dfx identity get-principal
把本地身份连接到主网
dfx identity --network ic set-wallet --force dzrcz-6qaaa-aaaai-qbfva-cai
钱包
dfx wallet --network=ic balance
把网站部署到主网
dfx deploy --network=ic
在网络里面访问
在ic加上ic0.app
https://zmcul-jyaaa-aaaai-qfi2q-cai.ic0.app/
5.安装node.js
https://nodejs.org/en/
npm -v
node -v
验证
创建一个nodeTest.js文件
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type" : "text/plain"
});
response.write("Welcome to Nodejs");
response.end();
}).listen(8000, "127.0.0.1");
console.log("Creat server on http://127.0.0.1:8000/");
2.终端进入 nodetest.js 所在目录, 输入 node nodeTest
3.打开浏览器,输入c, 如果无法打开,可以输入输入http://localhost:8000/。