快速入门
准备工作
本电脑系统:macOS Mojave 10.14 / 8G 1.8 GHz Intel Core i5
本文档是Cyber Miles的高级开发语言Lity版的”Hello Word”
操作过程中有任何问题需要帮助的,见文章底部
安装好:git ,homebrew , cmake (老鸟如果已安装,请跳过)
1.1 安装homebrew:
1 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
测试brew安装是否成功:
1 brew help
1.2 安装Git:
1 | brew install git |
1.3 安装cmake:
1 | brew install cmake |
==准备工作完成后,开始安装Lity==
2.1安装lity
1 | git clone https://github.com/CyberMiles/lity.git |
安装完成后,依次输入
1 | cd lity |
1 | mkdir build |
1 | source ./scripts/install_ |
(这里如果有问题,请看备注)
==显示“进程已完成”后,重新新建一个标签,输入以下代码。==
依次输入
1 | cd build |
1 | cmake .. |
安装成功
继续输入
1 | make |
检查是否成功
1 | ./lityc/lityc --help |
2. 运行私有链(启动CyberMiles节点)
2.1.安装docker: https://docs.docker.com/docker-for-mac/install/
使用brew下载并安装1
brew cask install docker
2.2在lauchpad中找到小🐳点击运行
运行成功小图标
附手动下载地址: https://download.docker.com/mac/stable/Docker.dmg
2.3.检查Docker安装成功
1 | docker run hello-world |
2.4 运行travis: https://travis.readthedocs.io/en/latest/getting-started.html#use-docker
使用docker下载travis的image
1 | docker run --rm -v ~/volumes/local:/travis cybermiles/travis node init --home /travis |
2.5 使用docker运行
1 | travis |
2.6 新开个终端,检测链上变化:
1 | docker logs -f travis |
2.7 再新建一个窗口,连接cybermiles节点:
1 | docker inspect -f '{{ .NetworkSettings.IPAddress }}' travis |
2.8 使用docker运行本地节点
1 | docker run --rm -it cybermiles/travis attach http://172.17.0.2:8545 |
3.1 准备账户
准备账户,在上一个窗口继续输入
1 | cmt.accounts |
或者1
personal.listAccounts
3.2查看账户信息:
1 | cmt.getBalance(cmt.accounts[0]) |
3.3 创建账户 CMT100为新账户的密码
1 | personal.newAccount('CMT100') |
3.4 给新账户转账
查看用户列表
1 | personal.listAccounts |
3.4 解锁账户
1 | personal.unlockAccount("0x7eff122b94897ea5b0e2a9abf47b86337fafebdc","1234"); |
3.5给新建的账户地址转账
1 | cmt.sendTransaction({from: '0x7eff122b94897ea5b0e2a9abf47b86337fafebdc', to: '0xc1f9378552bd55b29733f0915d8311071ed4143e', value: web3.toWei(99, 'cmt')}); |
3.6查看账户信息
1 | cmt.getBalance(cmt.accounts[2]) |
显示“9900000000000000”
3.7 解锁自己创建的账户
1 | personal.unlockAccount(cmt.accounts[2],’CMT100') |
3.8编写合约代码
新建终端 在==lity/build== 下创建1
vi hello.lity
写入内容:
pragma solidity ^0.4.23;
contract ReverseContract {
function reverse(string input) public returns(string) {
string memory output = eni(“reverse”, input);
return output;
}
}
写入内容后,保存
3.9 用lityc将源代码编译为字节代码
分别输入1
./lityc/lityc --bin hello.lity
1 | ./lityc/lityc --abi hello.lity |
4. 部署合约
4.1解锁账户
回到docker run 的终端窗口
输入:1
personal.unlockAccount(cmt.accounts[2],'CMT100');
4.2定义abi变量
ABI变量内容
1 | var helloContract=web3.cmt.contract([{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"reverse","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]); |
显示“undefined”
5.部署合约
5.1继续在连接本地节点终端窗口输入:
1 | var hello = helloContract.new( |
如果时间超时,需要重新解锁。
1 | personal.unlockAccount(cmt.accounts[2],'CMT100') |
5.2调用合约
1 | hello.reverse.call("hello,atao!",{from:cmt.accounts[2]}); |
笔记:
- if you see this:
Error: An unexpected error occurred during thebrew link
step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
then do this:
sudo chown -R $(whoami) $(brew –prefix)/
note the $(brew –prefix)/ …High Sierra doesn’t allow you to change permissions on /user/local directly)
sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
Last: source ./script/install_deps.sh
有任何问题可以加QQ解决:
QQ群1:832462204
QQ群2:875719854
CM官方文档:https://travis.readthedocs.io/en/latest/getting-started.html
Lity:https://www.litylang.org/gas/
lity入门: https://lity.readthedocs.io
libENI: https://libeni.readthedocs.io/en/latest/
Github:https://github.com/CyberMiles/lity
WEB3-CMT.JS: https://cybermiles.github.io/web3-cmt.js/api/
lity开发入门指南(有视频):https://dwz.cn/qDs8XQOt
如何利用Lity创新(有视频):https://dwz.cn/B63y9P1R
Lity如何防止合约错误:https://dwz.cn/4jMiQz5q
欢迎各位开发者到Github上提问,把有价值的问题留存下来,以便后面的开发者可以快速解决问题。
草莓100,别墅靠海.