Solidity 进阶

这里介绍 Solidity 的进阶概念。

单位 - unit

Solidity 引入了单位的概念,TVM 对以太坊 EVM 做了相关修改。所以合约里可以轻松进行 trxsun 的换算。

另外还有时间单位 seconds, minutes, hours, days, weeks. 基础单位是 seconds.

全局变量/全局函数

是合约代码编写过程中可用的函数和常量。

参考: https://solidity.readthedocs.io/en/v0.6.6/units-and-global-variables.html

Block 及 Transaction 处理

// 为兼容提供,在 TVM 中无具体意义
block.difficulty (uint): current block difficulty
gasleft() returns (uint256): remaining gas
block.gaslimit (uint): current block gaslimit
tx.gasprice (uint): gas price of the transaction

blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent, excluding current, blocks
block.coinbase (address payable): current block miner’s address
block.number (uint): current block number
block.timestamp (uint): current block timestamp as seconds since unix epoch

msg.data (bytes calldata): complete calldata
msg.sender (address payable): sender of the message (current call)
msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier)
msg.value (uint): number of wei sent with the message
msg.tokenvalue (uint): TRC10 token value
msg.tokenid (trcToken): TRC10 token 10
now (uint): current block timestamp (alias for block.timestamp)
tx.origin (address payable): sender of the transaction (full call chain)

address 成员函数

ABI Encoding and Decoding Functions

错误处理

数学和加密函数

内联汇编 - assembly

内部交易 - inline transaction / internal transaction

合约的 transfercreate ,及 call, suicide 调用,会生成内部交易。

其定义是:

目前 TRON 对合约创建合约的支持还不够完善。

最后更新于

这有帮助吗?