# Tooling

这里介绍各种合约开发相关工具。

## tron-solidity

`solc` 是标准的 Solidity 编译器， TRON 对此的 fork 修改位于 [tronprotocol/solidity](https://github.com/tronprotocol/solidity).

用法:

```
> solc --allow-paths `pwd` --overwirte -o ./out/ --abi --bin token/TRC20/TRC20.sol
...
```

### 相对于原始 solc 的修改

* 增加 `trcToken` 基础类型, int256
* 删除 `wei|szabo|finney|ether` 单位，增加 `sun|trx`
* 增加 `TOKENBALANCE` 指令, `0xd1`, 方法 `tokenBalance`
  * `address.tokenBalance(trcToken) -> uint`
* 增加 `address.transferToken(uint, trcToken)`
* 增加 `CALLTOKENVALUE`, `CALLTOKENID` 指令, `0xd2`, `0xd3`
  * `msg.tokenvalue: uint256`
  * `msg.tokenid: trcToken`
* `CALLVALUE` 更名 `CALLTOKEN`
* 增加 `ISCONTRACT` 指令
  * 隶属 `address.isContract`: bool
* 增加全局函数 `batchvalidatesign`
  * `bytes32 batchvalidatesign(bytes32 hash, bytes[] memory signatures, address[] memory addresses)`
  * 位图表示第 N 个地址验证成功
  * 最多同时验证 10 个签名
* 全局函数 `validatemultisign`
  * `bool batchvalidatesign(address address, uint256 permissionid, bytes32 content, bytes[] memory signatures)`
* 增加匿名合约相关函数
  * `verifyMintProof`
  * `verifyTransferProof`
  * `verifyBurnProof`
  * `pedersenHash`

理论上这些函数可以通过 library 方式实现对非 tvm 改版 Solidity 编译器的兼容。 官方应提供相应的 library 地址，作为标准参考实现。例如：

```javascript
pragma solidity >=0.4.22 <0.6.0;

library Tron {

    function tokenBalance(address addr, uint256 tokenId) public view returns (uint256) {
        require(tokenId > 1000000);
        return addr.tokenBalance(tokenId);
    }

    function transferToken(address payable addr, uint256 tokenId, uint256 amount) public  {
        require(tokenId > 1000000);
        addr.transferToken(amount, tokenId);
    }
}
```

```javascript
pragma solidity >=0.4.22 <0.6.0;

import "./libtron.sol";

contract TestCall {
    function run() external view returns (uint256) {
        // address converted to 20-bytes checksum address
        address myAddress = 0x5CbDd86a2FA8Dc4bDdd8a8f69dBa48572EeC07FB;
        return Tron.tokenBalance(myAddress, 1000001);
    }
}
```

### 注意事项

{% hint style="info" %}
tron-solidity 没有遵循 solidity 的命名规范，混用大小写。
{% endhint %}

{% hint style="info" %}
`ecrecover()` 未处理 TRON 地址对 rec\_id 的修改，所以需要兼容性判断，若 `rec_id < 27` 则 `rec_id += 27`.
{% endhint %}

{% hint style="info" %}
tron-solidiy 缺乏地址格式相关工具，需要手动处理。即，没有 T-address 到二进制地址的处理函数。
{% endhint %}

{% hint style="info" %}
在虚拟机内部，地址是 20 字节格式，与 EVM 一致。
{% endhint %}

## TRON-IDE

<https://www.tronide.io/>, forked from remix, the ethereum IDE.

Doc: <https://tron-ide.readme.io/>

基本使用很简单，但对 library 支持欠佳。

## TronBox

[TronBox](https://github.com/TRON-US/tronbox), forked from Truffle.

## wallet-cli

<https://github.com/tronprotocol/wallet-cli>

官方命令行工具，功能全面。但写的很傻逼。

## wallet-cli(rust-tron)

Doc: <https://github.com/andelf/rust-tron/blob/master/docs/contract.md>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andelf.gitbook.io/tron/smart-contract/tooling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
