进行交易时 "tx" 是什么

solidity what is "tx" when making a transaction

我是 solidity 的初学者,我一直在玩 truffle,当我发送交易时,我得到一个交易日志,其中一个值是“tx”,其他标签很容易解释,但我不知道真的看不懂这个代表什么吗?

那么represent/what你能用这些信息做什么?

谢谢

tx 代表“交易”,但它是两种不同的东西,具体取决于您谈论的是 Solidity 还是 Truffle。


The "Block and Transaction Properties" docs 对于 Solidity 说 tx 是全局可用的变量之一。

There are special variables and functions which always exist in the global namespace and are mainly used to provide information about the blockchain or are general-use utility functions.

根据相同的文档,上面应该有两个全局字段:

  • tx.origin

sender of the transaction (full call chain)

  • tx.gasprice

gas price of the transaction


The "Processing Transaction Results" docs 对于 Truffle 状态 tx 是包含交易哈希的字符串。

When you make a transaction, you're given a result object that gives you a wealth of information about the transaction.

[...] Specifically, you get the following:

result.tx (string) - Transaction hash

result.logs (array) - Decoded events (logs)

result.receipt (object) - Transaction receipt (includes the amount of gas used)

For more information, please see the README in the @truffle/contract package.