Skip to content

Commit

Permalink
translation
Browse files Browse the repository at this point in the history
  • Loading branch information
zonLi committed May 9, 2019
1 parent 1cc8f10 commit 4fba536
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions TRX/Tron-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,25 +680,25 @@ If contract executes successfully without any exception, the energy needed for t

##### Note
1. when developer create a contract, do not set consume_user_resource_percent to 0, which means developer will undertake all the energy consumption. If Assert-style error comes out, it will consume all energy from the developer itsef. Assert-style error introduction, refer to (https://github.com/tronprotocol/Documentation/blob/master/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3/%E8%99%9A%E6%8B%9F%E6%9C%BA/%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86.md).
To avoid unnecessary lost, consume_user_resource_percent is recommended 10-100
To avoid unnecessary lost, 10-100 is recommended for consume_user_resource_percent

## 5.4 智能合约开发工具介绍
## 5.4 Smart Contract Development Tool
### 5.4.1 TronStudio
波场智能合约开发工具。提供可视化界面,支持开发者对solidity语言智能合约进行编译,调试,运行等功能。
Support the build, debug, run, etc. for solidity language written smart contract
https://developers.tron.network/docs/tron-studio-intro
### 5.4.2 TronBox
波场智能合约部署工具。支持solidity语言智能合约的编译,部署,移植等功能。
Support the build, deploy, transplant, etc. for solidity language written smart contract
https://developers.tron.network/docs/tron-box-user-guide
### 5.4.3 TronWeb
波场智能合约开发使用的http api库。提供和主链交互,合约部署调用等接口。
Provide http api service for the usage of smart contract
https://developers.tron.network/docs/tron-web-intro
### 5.4.4 TronGrid
波场智能合约事件查询服务。可以查询智能合约中写入的事件log信息。
Provide smart contract event query service
https://developers.tron.network/docs/tron-grid-intro

## 5.5 使用命令行工具进行智能合约开发
## 5.5 Using Command Lines Tool to Develop Smart Contract

在tron上进行智能合约的开发,除了使用现有的工具之(tron-studio)外,也可以直接使用wallet-cli命令行工具进行智能合约的开发,编译和部署。编写智能合约,可以使用使用TronStudio进行编译、调试等前期的开发工作。 当合约开发完成之后,可以把合约复制到[SimpleWebCompiler](https://github.com/tronprotocol/tron-demo/tree/master/SmartContractTools/SimpleWebCompiler)中进行编译,获取ABI和ByteCode。 我们提供一个简单的数据存取的合约代码示例,以这个示例来说明编译、部署、调用的步骤。
First you can use TronStudio to write, build and debug the smart contract. After you finish the development of the contract, you can copy it to [SimpleWebCompiler](https://github.com/tronprotocol/tron-demo/tree/master/SmartContractTools/SimpleWebCompiler) to compile to get ABI and ByteCode. We provide a simple data read/write smart contract code example to demonstrate:

```
pragma solidity ^0.4.0;
Expand All @@ -716,110 +716,110 @@ contract DataStore {
}
```

### 启动私有链
### Start a Private Net

确保前提条件中,私有链已经在本地部署完成。可以检查FullNode/logs/tron.log中,是否有持续产块的log信息出现:“Produce block successfully
Make sure the fullnode code has been deployed locally, you can check if 'Produce block successfully' log appears in FullNode/logs/tron.log

### 开发智能合约
### Develop a Smart Contract

把上述代码复制到remix中编译,调试,确保代码的逻辑是自己需要的,编译通过,没有错误
Copy the code example above to remix to debug

### 在SimpleWebCompiler编译得到ABI和ByteCode
### Compile in SimpleWebCompiler for ABI and ByteCode

因为波场的编译器与以太坊的编译略有差异,正在与Remix集成中,所以临时采用改方案获取ABI和ByteCode,而不是通过Remix直接获取ABI和ByteCode。
把上述代码复制到SimpleWebCompiler中,点击Compile按钮,获取ABI和ByteCode。
Copy the code example above to SimpleWebCompiler to get ABI and ByteCode
Because TRON's compiler is a little different from Ethereum, so you can not get ABI and ByteCode by using Remix. But it will soon be supported.

### 通过Wallet-cli部署智能合约
### Using Wallet-cli to Deploy

下载Wallet-Cli,文件然后编译。
Download Wallet-Cli and build

```
shell
# 下载源代码
# download cource code
git clone https://github.com/tronprotocol/wallet-cli
cd wallet-cli
# 编译
# build
./gradlew build
cd build/libs
```

> Note:wallet-cli 默认的配置会连接本地127.0.0.1:50051的 fullnode,如果开发者需要连接不同的其他节点或者端口可在 config.conf 文件中进行修改
> Note: You need to change the node ip and port in config.conf
启动wallet-cli
start wallet-cli

```
java -jar wallet-cli.jar
```

启动之后,可在命令中交互式输入指令。导入私钥,并查询余额是否正确
after started, you can use command lines to operate:

```
importwallet
<输入你自己的设定的钱包密码2次>
<输入私钥:da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0>
<input your password twice for your account>
<input your private key>
login
<输入你自己的设定的钱包密码>
<input your password you set>
getbalance
```

部署合约
deploy contract

```
Shell
# 合约部署指令
# contract deployment command
DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent <value> <library:address,library:address,...>
# 参数说明
contract_name:自己制定的合约名
ABI:从SimpleWebCompiler中获取到的 ABI json 数据
bytecode:从SimpleWebCompiler中获取到的二进制代码
constructor:部署合约时,会调用构造函数,如果需要调用,就把构造函数的参数类型填写到这里,例如:constructor(uint256,string),如果没有,就填写一个字符#
params:构造函数的参数,使用逗号分隔开来,例如 1,"test" ,如果没有构造函数,就填写一个字符#
fee_limit:本次部署合约消耗的TRX的上限,单位是SUN(1 SUN = 10^-6 TRX),包括CPU资源、STORAGE资源和可用余额的消耗
consume_user_resource_percent:指定的使用该合约用户的资源占比,是[0, 100]之间的整数。如果是0,则表示用户不会消耗资源。如果开发者资源消耗完了,才会完全使用用户的资源。
value:在部署合约时,给该合约转账金额,使用十六进制32位表示
library:address,library:address,...:如果合约包含library,则需要在部署合约的时候指定library的地址,具体见下文;没有library的话则不需要填写。
# 运行例子
# parameters
contract_name: Contract name
ABI: ABI from SimpleWebCompiler
bytecode: ByteCode from SimpleWebCompiler
constructor: When deploy contract, this will be called. If is needed, write as constructor(uint256,string). If not, just write #
params: The parameters of the constructor, use ',' to split, like 1, "test", if no constructor, just write #
fee_limit: The TRX consumption limit for the deployment, unit is SUN(1 SUN = 10^-6 TRX)
consume_user_resource_percent: Consume user's resource percentage. It should be an integer between [0, 100]. if 0, means it does not consume user's resource until the developer's resource has been used up
value: The amount of TRX transfer to the contract when deploy
library: If the contract contains library, you need to specify the library address
# example
deploycontract DataStore [{"constant":false,"inputs":[{"name":"key","type":"uint256"},{"name":"value","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"key","type":"uint256"}],"name":"get","outputs":[{"name":"value","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] 608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029 # # false 1000000 30 0
部署成功会显示Deploy the contract successfully
If it is deployed successfully, it will return 'Deploy the contract successfully'
```

得到合约的地址
get the contract address

```
Your smart contract address will be: <合约地址>
Your smart contract address will be: <contract address>
# 在本例中
# in this example
Your smart contract address will be: TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
```

调用合约存储数据、查询数据
call the contract to store data, query data

```
Shell
# 调用合约指令
# call contract command
triggercontract <contract_address> <method> <args> <is_hex> <fee_limit> <value>
# 参数说明
contract_address:即之前部署过合约的地址,格式 base58,如:TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
method:调用的函数签名,如set(uint256,uint256)或者 fool(),参数使用','分割且不能有空格
args:如果非十六进制,则自然输入使用','分割且不能有空格,如果是十六进制,直接填入即可
is_hex:输入参数是否为十六进制,false 或者 true
fee_limit:和deploycontract的时候类似,表示本次部署合约消耗的TRX的上限,单位是SUN(1 SUN = 10^-6 TRX),包括CPU资源、STORAGE资源和可用余额的消耗。
value:在部署合约时,给该合约转账金额,使用十六进制32位表示
# parameters
contract_address: Contract address, like TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
method: The method called, like set(uint256,uint256) or fool(), use ',' to split the parameters. Do not leave space between parameters
args: The parameters passed to the method called, use ',' to split the parameters. Do not leave space between parameters
is_hex: whether the input parameters is Hex, false or true
fee_limit: The TRX consumption limit for the trigger, unit is SUN(1 SUN = 10^-6 TRX)
value: The amount of TRX transfer to the contract when trigger
# 调用的例子
## 设置 mapping 1->1
# trigger example
## set mapping 1->1
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 set(uint256,uint256) 1,1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000
## 取出 mapping key = 1的 value
## get mapping key = 1
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 get(uint256) 1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000
```

如果调用的函数是 constant viewwallet-cli 将会直接返回结果
If the function called is constant or view, wallet-cli will return the result directly.

如果包含library,则需要在部署合约之前先部署library,部署完library之后,知道了library地址,将地址填进library:address,library:address,...
If it contains library, before deploy the contract you need to deploy the library first. After you deploy library, you can get the library address, then fill the address in library:address,library:address,...

```
# 比如使用remix生成的合约,bytecode是
Expand Down

0 comments on commit 4fba536

Please sign in to comment.