合约文件目录
所有合约都位于项目的 contracts/
目录中。 由于合约是用Solidity 语言编写的,所有包含合约的文件都将具有 .sol
文件扩展名。 相关的 Solidity 库也将有一个.sol
扩展名。
使用 tronbox init
命令创建的空 TronBox 工程会生成一个用于部署的 Migrations.sol
合约文件。 如果我们使用 TronBox Box 来创建工程,则会有多个合约文件。
编译命令
要编译 TronBox 项目里的合约,请切换到项目工程所在根目录,然后在终端中键入以下内容:
tronbox compile
首次运行时,将编译所有合约。 在后续运行中,TronBox 将仅编译自上次编译以来有更改的合约。 如果我们想覆盖此行为,可以使用 --all
选项运行上面的命令。
构建 Artifacts
编译的目标文件 Artifacts 将放在 build/contracts/
目录中,相对于项目根目录(如果该目录不存在,将创建该目录。)
这些 Artifacts 是 TronBox 内部工作的组成部分,它们在成功部署应用程序中起着重要作用。 我们不应编辑这些文件,因为这些文件将被合约编译和部署覆盖。
引入合约依赖文件
我们可以使用 Solidity 的 import
命令声明合约依赖文件。 TronBox 将以正确的顺序编译合约,并确保将所有依赖文件发送给编译器。 可以通过两种方式指定依赖关系:
通过文件名导入依赖文件
要从单独的文件导入合约,请将以下代码添加到 Solidity 源文件中:
import './AnotherContract.sol';
这将导入 AnotherContract.sol
中的所有合约,这里 AnotherContract.sol
是在当前编写的合约目录下。
Solidity 还有其他的导入语法,可以参考Solidity 文档:导入源文件了解更多信息。
从外部包导入合约
TronBox 支持通过 NPM
安装的依赖。 可使用以下语法把依赖导入合约:
import 'somepackage/SomeContract.sol';
这里,somepackage
表示通过 NPM
安装的包,SomeContract.sol
表示该包提供的 Solidity 源文件。
有关如何使用 TronBox 软件包管理功能的更多信息,请参阅 TronBox NPM 文档 。
TIP-467 Stake 2.0 - the new stake mechanism
在 TronBox v3.1.1 版本中支持了 TRON Compiler Solidity v0.8.17
该版本支持 TIP-467 中引入的新指令和预编译合约。
TVM: Introduce freezebalancev2(uint256,uint256) in Solidity.
TVM: Introduce unfreezebalancev2(uint256,uint256) in Solidity.
TVM: Introduce cancelallunfreezev2() in Solidity.
TVM: Introduce withdrawexpireunfreeze() in Solidity.
TVM: Introduce <address payable>.delegateResource(uint256,uint256) in Solidity.
TVM: Introduce <address payable>.unDelegateResource(uint256,uint256) in Solidity.
TVM: Introduce new magic type chain in Solidity and the parameters that can be queried include chain.totalNetLimit, chain.totalNetWeight, chain.totalEnergyCurrentLimit, chain.totalEnergyWeight and chain.unfreezeDelayDays.
TVM: Introduce <address>.availableUnfreezeV2Size() in Solidity.
TVM: Introduce <address>.unfreezableBalanceV2(uint256) in Solidity.
TVM: Introduce <address>.expireUnfreezeBalanceV2(uint256) in Solidity.
TVM: Introduce <address>.delegatableResource(uint256) in Solidity.
TVM: Introduce <address>.resourceV2(address,uint256) in Solidity.
TVM: Introduce <address>.checkUnDelegateResource(address,uint256) in Solidity.
TVM: Introduce <address>.resourceUsage(uint256) in Solidity.
TVM: Introduce <address>.totalResource(uint256) in Solidity.
TVM: Introduce <address>.totalDelegatedResource(uint256) in Solidity.
TVM: Introduce <address>.totalAcquiredResource(uint256) in Solidity.