CyberMiles· Lity开发者文档翻译

Lity是什么?

Lity是一种用于建立区块链智能合约的新编程语言。它由CyberMiles区块链上的动态可扩展语言,编译器和虚拟机组成。它是Solidity语言的超集,具有更高的可扩展性,性能更好和更安全。尤其是:

• LibENI动态VM扩展允许将本机功能即时添加到虚拟机,而无需停止、分叉或升级区块链。

• Lity语言的内置功能计划允许智能合约安排未来某一时间自动执行的计时器任务(schedule timertasks),这是许多现实商业合约所要求的,例如信托,遗嘱,分期付款,保险,股票期权和投资回报。

• Lity语言的内置功能 isValidator 允许智能合约检查交易发起人是否是CyberMiles区块链的当前验证人。通过ValidatorOnly修饰符,我们可以创建“可信”智能合约(“trusted” smart contracts),只能由CyberMiles区块链上的验证人更新。这种可信赖的智能合约的一个常见使用场景是让它们充当提供链下和跨链状态的预言机。

• 即将推出的Lity Rules Engine允许将正式的业务规则嵌入到智能合约中。这可以大大提高开发人员的工作效率并减少错误。

• Lity 语言可防止整数溢出错误。它引入新的数字类型称为safeuint。它是一个无符号整数 (uint) 但是所有safeuint操作都自动包装在SafetMath函数中。此外,CyberMiles虚拟机(CVM)在运行时检测并停止整数溢出。使用safeuint和CVM消除了大量的智能合约错误,这些损失曾引发大量的资金损失.

• Lity语言支持固定点实数(fixed point real numbers),而不是Solidity中的仅整数算术。

• Lity 智能合约支持设定gas费(support alternative gas prices)。例如,系统可以为某些类型的合约提供gas折扣,以促进区块链上的某些使用场景。

• Lity编译器提供部署Lity智能合约之前用于安全和错误检查的工具。 Lity编译器中的ERC检查器(ERC checker)分析源代码并自动检查合约是否符合已知的ERC标准。编译器还与Oyente静态分析器(Oyente static analyzer)集成,以检测编译的字节码中的常见错误模式。

很感兴趣?从这里开始吧!

Lity这个名字是向Solidity致敬,并且致力于更灵活/可扩展(流动性)和更高性能(可燃性)。Lity由CyberMiles 基金会和Skymizer合作开发,并由GPL作为免费软件发布。保留所有权利。

开始吧!

首先,您需要下载并安装Lity编译器。 然后,编写并编译Lity智能合约。 接下来,您可以启动CyberMiles节点并在区块链上执行智能合约。

下载和安装

安装 Lity, 从GitHub上的源代码开始.
或者, 可以下载Lity发布的二进制码并将可执行文件lityc提取到本地目录~/lityc/。

Reverse Hello World

The code below shows a simple Lity contract with a libENI call. The single libENI call costs hundreds of millions Ethereum gas to run when implemented in Solidity – it showcases the capability of Lity and libENI. While all Solidity smart contracts work on Lity, this example uses Lity-specific features and will not run on Solidity / Ethereum. First, create the text file Reverse.lity with the following content. It uses a libENI extension function reverse, which is not available in standard Solidity.

下面的代码显示了一个带有libENI调用的简单Lity合约。 当在Solidity中实现时,单个libENI调用会花费数亿个以太坊gas才能运行 - 它展示了Lity和libENI的功能。 虽然所有Solidity智能合约都适用于Lity,但此示例使用Lity特定功能,无法在Solidity / Ethereum上运行。 首先,使用以下内容创建文本文件Reverse.lity。 它使用libENI扩展函数reverse,这在标准Solidity中不可用。

pragma solidity ^0.4.23;
  
contract ReverseContract {
  function reverse(string input) public returns(string) {
    string memory output = eni("reverse", input);
    return output;
  }
}

Next, let’s use lityc to compile the source into byte code. 接下来,让我们使用lityc将源代码编译为字节代码。

$ ./lityc/lityc --bin Reverse.lity
======= ./Reverse.lity:ReverseContract =======
Binary:
608060405234...

Then, we also use lityc to generate the interface definition required by the virtual machine to register the contract. 然后,我们还使用lityc生成虚拟机登记合约所需的接口定义。

$ ./lityc/lityc --abi Reverse.lity
======= ./Reverse.lity:ReverseContract =======
Contract JSON ABI
[{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"reverse","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
运行CyberMiles节点

The Lity software we downloaded includes the lityc compiler and development tools. But in order to run the smart contract, we also need the Lity virtual machine with libENI support. You will need to run a CyberMiles blockchain node for this.
The easiest way to do this is to simply run a Docker image for a local single node. Make sure that you get to the step where you connect to the node’s web3-cmt console.

我们下载的Lity软件包括lityc编译器和开发工具。 但是为了运行智能合约,我们还需要支持libENI的Lity虚拟机。 您需要为此运行CyberMiles区块链节点。
最简单的方法是简单地为本地单个节点运行Docker镜像。 确保进入连接到节点的web3-cmt控制台的步骤。
或者,如果您运行的是CentOS或Ubuntu Linux发行版,您也可以从源代码构建。

After you have completed the test on the local single node, you can configure the node to connect to an existing CyberMiles network, and sync to become a full node on the blockchain. That allows your smart contracts to run on all nodes of the blockchain. 在本地单节点上完成测试后,您可以将节点配置为连接到现有的CyberMiles网络,并同步,以成为区块链上的完整节点。 这使得您的智能合约在区块链的所有节点上运行。

运行智能合约

接下来,从附加的web3-cmt控制台,您可以使用从前文的合约生成的abi和字节码来实现智能合约并接收部署合约的地址。

> personal.unlockAccount(cmt.accounts[0],'1234');
> bytecode="0x608060405234801561001057600080fd5b50610272806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063064767aa14610046575b600080fd5b34801561005257600080fd5b506100ad600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610128565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ed5780820151818401526020810190506100d2565b50505050905090810190601f16801561011a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0400000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528480516020019081604051908101604052905b6020831015156101f057805182526020820191506020810190506020830392506101cb565b6001836020036101000a0d8019825116818451168082178552505050505050806040518190039052907f7265766572736500000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a723058204272fd3392dd08f71aad18d99b3593526f5b5b8859012881cab51740081dd8360029"
> abi = [{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"reverse","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
> contract = web3.cmt.contract(abi);
> contractInstance = contract.new(
   {
     from: web3.cmt.accounts[0],
     data: bytecode,
     gas: "4700000"
   },
   function(e, contract) {
     console.log("contract address: " + contract.address);
     console.log("transactionHash: " + contract.transactionHash);
   }
 );

接下来,您可以在已部署的合约实例上调用libENI方法。

> contractInstance.reverse.call("hello", {from: cmt.accounts[0]})
olleh

完成!

启动

在本文档中,我们将讨论如何在您的计算机上创建和运行单个节点CyberMiles区块链。这使得您能够连接和测试基本功能,如代币交易,给验证人做权益投票和取消验投票,治理和智能合约。

使用Docker

最简单的启动方法是使用我们的预构建Docker镜像。请确保您已安装Docker并且Docker可以在没有sudo的情况下工作。

初始化

让我们首先初始化Travis构建的docker窗图像。

docker run --rm -v ~/volumes/local:/travis ywonline/travis node init --home /travis

节点的数据目录是本地计算机上的~/volumes/local。

运行

现在你可以在docker中运行 CyberMiles Travis 节点。

docker run --name travis -v ~/volumes/local:/travis -t -p 26657:26657 -p 8545:8545 ywonline/travis node start --home /travis

此时,您可以按Ctrl-C退出终端,travis将继续在后台运行。 您可以通过以下docker命令随时查看CyberMiles Travis节点的日志。

docker logs -f travis

您可以在日志中看到如下所示的区块。

INFO [07-14|07:23:05] Imported new chain segment               blocks=1 txs=0 mgas=0.000 elapsed=431.085µs mgasps=0.000 number=163 hash=05e16c…a06228
INFO [07-14|07:23:15] Imported new chain segment               blocks=1 txs=0 mgas=0.000 elapsed=461.465µs mgasps=0.000 number=164 hash=933b97…0c340c
连接

您可以通过附加Travis客户端的实例来连接到本地CyberMiles节点。

# Get the IP address of the travis node
docker inspect -f '{{ .NetworkSettings.IPAddress }}' travis
172.17.0.2

# Use the IP address from above to connect
docker run --rm -it ywonline/travis attach http://172.17.0.2:8545

它打开web3-cmt JavaScript控制台以与虚拟机进行交互。 下面的示例显示了如何解锁coinbase帐户,以便您有代币可以使用。

Welcome to the Travis JavaScript console!

instance: vm/v1.6.7-stable/linux-amd64/go1.9.3
coinbase: 0x7eff122b94897ea5b0e2a9abf47b86337fafebdc
at block: 231 (Sat, 14 Jul 2018 07:34:25 UTC)
 datadir: /travis
 modules: admin:1.0 cmt:1.0 eth:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0

> personal.unlockAccount('0x7eff122b94897ea5b0e2a9abf47b86337fafebdc', '1234')
true
>
源代码构建

目前,我们仅支持CentOS 7和Ubuntu 16.04 Linux发行版的源代码构建。

前提条件

您必须安装GO语言版本1.10+才能构建和运行Travis节点。获得GO 1.10的最简单方法是通过GVM。以下是Linux服务器上的命令。

$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
$ vim ~/.bash_profile
inset into the bash profile: source "$HOME/.bashrc"
log out and log in
$ sudo apt-get install bison
$ gvm version
output should look like: Go Version Manager v1.0.22 installed at /home/myuser/.gvm
$ gvm install go1.10.3
$ gvm use go1.10.3 --default
Build建立

首先,我们需要从Github检出Travis的正确分支:

go get github.com/CyberMiles/travis (ignore if an error occur)
cd $GOPATH/src/github.com/CyberMiles/travis
git checkout master

接下来,我们需要构建libENI并将其放入默认的Travis数据目录~/.travis/.

sudo rm -rf ~/.travis
wget -O $HOME/libeni.tgz https://github.com/CyberMiles/libeni/releases/download/v1.3.2/libeni-1.3.2_ubuntu-16.04.tgz
tar zxvf $HOME/libeni.tgz -C $HOME
mkdir -p $HOME/.travis/eni
cp -r $HOME/libeni-1.3.2/lib $HOME/.travis/eni/lib

目前libENI只能在Ubuntu 16.04和CentOS 7上运行。如果您的操作系统是CentOS,请使用另外的下载链接。链接在这里:https://github.com/CyberMiles/libeni/releases

现在,我们可以构建和安装Travis二进制文件
。它会将其他配置文件填充到~/.travis/

cd $GOPATH/src/github.com/CyberMiles/travis
make all

如果系统在最后一步找不到glide,请确保$ PATH变量下有$ GOPATH / bin

运行

让我们使用 ~/.travis/ data目录在本地启动Travis节点。

travis node init
travis node start
Connect连接

You can connect to the local CyberMiles node by attaching an instance of the Travis client. 您可以通过附加Travis客户端的实例来连接到本地CyberMiles节点。

travis attach http://localhost:8545

It opens the web3-cmt JavaScript console to interact with the virtual machine. The example below shows how to unlock the coinbase account so that you have coins to spend. 它打开web3-cmt JavaScript控制台以与虚拟机进行交互。下面的示例显示了如何解锁coinbase帐户,以便您可以使用代币。

Welcome to the Travis JavaScript console!

instance: vm/v1.6.7-stable/linux-amd64/go1.9.3
coinbase: 0x7eff122b94897ea5b0e2a9abf47b86337fafebdc
at block: 231 (Sat, 14 Jul 2018 07:34:25 UTC)
 datadir: /travis
 modules: admin:1.0 cmt:1.0 eth:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0

> personal.unlockAccount('0x7eff122b94897ea5b0e2a9abf47b86337fafebdc', '1234')
true
>
测试交易

您现在可以在帐户之间发起交易,如下

personal.unlockAccount("from_address")
cmt.sendTransaction({"from": "from_address", "to": "to_address", "value": web3.toWei(0.001, "cmt")})

接下来,您可以在>提示符下将以下脚本粘贴到Travis客户端控制台中

function checkAllBalances() {
  var totalBal = 0;
  for (var acctNum in cmt.accounts) {
      var acct = cmt.accounts[acctNum];
      var acctBal = web3.fromWei(cmt.getBalance(acct), "cmt");
      totalBal += parseFloat(acctBal);
      console.log("  cmt.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " CMT");
  }
  console.log("  Total balance: " + totalBal + "CMT");
};

您现在可以在控制台中运行脚本,并查看结果。

> checkAllBalances();
cmt.accounts[0]:      0x6....................................230      balance: 466.798526 CMT
cmt.accounts[1]:      0x6....................................244      balance: 1531 CMT
Total balance: 1997.798526CMT

部署测试链节点

在本文档中,我们将讨论如何连接到CyberMiles Travis 测试链。我们将介绍Docker和“从源代码构建”方案。如果您不熟悉CyberMiles,则部署Docker节点可能更容易。
虽然我们强烈建议您运行自己的Travis节点,但您也可以要求直接访问由CyberMiles 基金会维护的其中一个节点。发送电子邮件至[email protected]以申请访问凭证。您仍然需要来自Docker或源(source)的travis客户端来访问节点。

Binary二进制文件

确保您的操作系统是Ubuntu 16.04或CentOS 7

发布页面下载预构建的二进制文件

mkdir -p $HOME/release
cd $HOME/release

# if your os is Ubuntu
wget https://github.com/CyberMiles/travis/releases/download/vTestnet/travis_vTestnet_ubuntu-16.04.zip
unzip travis_vTestnet_ubuntu-16.04.zip

# or if your os is CentOS
wget https://github.com/CyberMiles/travis/releases/download/vTestnet/travis_vTestnet_centos-7.zip
unzip travis_vTestnet_centos-7.zip
获取 Travis 测试链配置
rm -rf $HOME/.travis
cd $HOME/release
./travis node init --env testnet
curl https://raw.githubusercontent.com/CyberMiles/testnet/master/travis/init/config/config.toml > $HOME/.travis/config/config.toml
curl https://raw.githubusercontent.com/CyberMiles/testnet/master/travis/init/config/genesis.json > $HOME/.travis/config/genesis.json

将您的名字从默认名称更改为本地Change your name from default name local

cd $HOME/.travis
vim $HOME/.travis/config/config.toml
# moniker = ""
# here you can change your name

将 libeni 复制到默认Travis data 目录中

mkdir -p $HOME/.travis/eni
cp -r $HOME/release/lib/. $HOME/.travis/eni/lib

# set env variables for eni lib
export ENI_LIBRARY_PATH=$HOME/.travis/eni/lib
export LD_LIBRARY_PATH=$HOME/.travis/eni/lib

启动节点并加入Travis 测试链

cd $HOME/release
./travis node start

Docker

准备条件

请设置docker

Docker Image

Docker image for Travis is stored on Docker Hub. TestNet environment is using the ‘lastest’ branch which can be pulled automatically from Travis:

$ docker pull ywonline/travis

Note: Configuration and data will be stored at /travis directory in the container. The directory will also be exposed as a volume. The ports 8545, 26656 and 26657 will be exposed for connection.

获得 Travis 测试链配置

点击Github repo查看Travis测试链配置. 将配置文件 $HOME/.travis放到目录中:

$ cd
$ sudo rm -rf $HOME/.travis
$ git clone https://github.com/CyberMiles/testnet.git
$ cd testnet/travis
$ git pull
$ cp -r init $HOME/.travis
启动节点并且加入Travis测试链

First change your name from default name首先将你的名称从默认名称修改 local

$ vim ~/.travis/config/config.toml
# moniker = ""
# here you can change your name
运行docker Travis 应用:
$ docker run --name travis -v $HOME/.travis:/travis -p 26657:26657 -p 8545:8545 -t ywonline/travis node start --home /travis

Now your node is syncing with TestNet, the output will look like the following. Wait until it completely syncs.现在您的节点正在与TestNet同步,输出将如下所示。 等到它完全同步。

INFO [07-20|03:13:26.229] Imported new chain segment               blocks=1 txs=0 mgas=0.000 elapsed=1.002ms   mgasps=0.000    number=3363 hash=4884c0…212e75 cache=2.22mB
I[07-20|03:13:26.241] Committed state                              module=state height=3363 txs=0 appHash=3E0C01B22217A46676897FCF2B91DB7398B34262
I[07-20|03:13:26.443] Executed block                               module=state height=3364 validTxs=0 invalidTxs=0
I[07-20|03:13:26.443] Updates to validators                        module=state updates="[{\"address\":\"\",\"pub_key\":\"VPsUJ1Eb73tYPFhNjo/8YIWY9oxbnXyW+BDQsTSci2s=\",\"power\":27065},{\"address\":\"\",\"pub_key\":\"8k17vhQf+IcrmxBiftyccq6AAHAwcVmEr8GCHdTUnv4=\",\"power\":27048},{\"address\":\"\",\"pub_key\":\"PoDmSVZ/qUOEuiM38CtZvm2XuNmExR0JkXMM9P9UhLU=\",\"power\":27048},{\"address\":\"\",\"pub_key\":\"2Tl5oI35/+tljgDKzypt44rD1vjVHaWJFTBdVLsmcL4=\",\"power\":27048}]"

To access the TestNet type the following in a seperte terminal console to get your IP address then use your IP address to connect to the TestNet.
要访问TestNet,请在单独的终端控制台中键入以下内容以获取您的IP地址,然后使用您的IP地址连接到TestNet。

$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' travis
172.17.0.2										
$ docker run --rm -it ywonline/travis attach http://172.17.0.2:8545

Now, you should see the web3-cmt JavaScript console, you can now jump to the “Test transactions” section to send test transactions.
现在,您应该看到web3-cmt JavaScript控制台,您现在可以跳转到“测试事务”部分来发送测试事务。

从源头构建

准备条件

Please install Travis via source builds. (STOP before you connect to a local node)请通过源代码构建安装Travis。 (在连接到本地节点之前停止)

获取Travis TestNet配置

Checkout the Travis TestNet config from our Github repo. Place the config files in the $HOME/.travis目录中:

$ cd
$ sudo rm -rf $HOME/.travis
$ git clone https://github.com/CyberMiles/testnet.git
$ cd testnet/travis
$ git pull
$ cp -r init $HOME/.travis
启动节点并加入Travis测试链

启动Travis 应用:

$ travis node start --home ~/.travis

Now your node is syncing with TestNet, the output will look like the following. Wait until it completely syncs. 现在您的节点正在与测试链同步,输出将如下所示。等待,直到完全同步。

INFO [07-20|03:13:26.229] Imported new chain segment               blocks=1 txs=0 mgas=0.000 elapsed=1.002ms   mgasps=0.000    number=3363 hash=4884c0…212e75 cache=2.22mB
I[07-20|03:13:26.241] Committed state                              module=state height=3363 txs=0 appHash=3E0C01B22217A46676897FCF2B91DB7398B34262
I[07-20|03:13:26.443] Executed block                               module=state height=3364 validTxs=0 invalidTxs=0
I[07-20|03:13:26.443] Updates to validators                        module=state updates="[{\"address\":\"\",\"pub_key\":\"VPsUJ1Eb73tYPFhNjo/8YIWY9oxbnXyW+BDQsTSci2s=\",\"power\":27065},{\"address\":\"\",\"pub_key\":\"8k17vhQf+IcrmxBiftyccq6AAHAwcVmEr8GCHdTUnv4=\",\"power\":27048},{\"address\":\"\",\"pub_key\":\"PoDmSVZ/qUOEuiM38CtZvm2XuNmExR0JkXMM9P9UhLU=\",\"power\":27048},{\"address\":\"\",\"pub_key\":\"2Tl5oI35/+tljgDKzypt44rD1vjVHaWJFTBdVLsmcL4=\",\"power\":27048}]"

To access the TestNet, type the following in a seperte terminal console (make sure that the seperate console also has travis environment):

$ travis attach http://localhost:8545

You should now the see the web3-cmt JavaScript console and can now test some transactions.
您现在应该看到web3-cmt JavaScript控制台,现在可以测试一些事务。

测试

In this section, we will use the travis client’s web3-cmt JavaScript console to send some transactions and verify that the system is set up properly. You can’t test transactions untill you are completely in sync with the testnet. It might take hours to sync.

创建和资助测试帐户

一旦将 travis 附加到上面的节点上, 就在测试网上创建两个账户.

Welcome to the Geth JavaScript console!
> personal.newAccount()
...

现在您已经在 Travis TestNET2上创建了两个帐户0x1234FROM 和0x1234DEST。是时候获得一些测试CMTS了。请访问下面的网站,并要求1000个TestNETCMTS帐户0x1234从。我们还将发送1000个测试token,由测试智能合同发送,到帐户0x1234FROM。
http://travis-faucet.cybermiles.io

Test transactions测试交易

You can test transactions between your two accounts. Remember to unlock both of your accounts. 您可以测试两个帐户之间的转账。记住解锁两个帐户

> personal.unlockAccount("0x1234FROM","password")
true
...
> cmt.sendTransaction({from:"0x1234FROM", to:"0x1234DEST",value:1000})
...
> cmt.getBalance("0x1234DEST")
...

您还可以为测试token测试智能合同转账,如下所示。

> abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"INITIAL_SUPPLY","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
> tokenContract = web3.cmt.contract(abi)
> tokenInstance = tokenContract.at("0xb6b29ef90120bec597939e0eda6b8a9164f75deb")
> tokenInstance.transfer.sendTransaction("0x1234DEST", 1000, {from: "0x1234FROM"})

After 10 seconds, you can check the balance of the receiving account as follows. 10秒后,您可以检查收款帐户的余额如下。

> tokenInstance.balanceOf.call("0x1234DEST")
Fee free transactions免费交易

在CyberMiles区块链上,我们可以做到大部分交易(除了重度用户或垃圾邮件发送者)免费。可以在 travis 客户端控制台中尝试。

> cmt.sendTransaction({from:"0x1234FROM", to:"0x1234DEST",value:1000,gasPrice:0})
...

要尝试免费的基于智能合约的token交易,请在travis客户端控制台中使用以下内容。

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上提问,把有价值的问题留存下来,以便后面的开发者可以快速解决问题。感谢哦

交流QQ群:832462204 875719854

你可能感兴趣的:(CyberMiles,Lity,区块链,公链,CMT,CyberMiles)