转换和理解 solidity 中的值
Converting and understanding values in solidity
我一直在研究 solidity,我一直在通过 etherscan 研究以太坊主网上的类似项目。我试图了解合同的某些功能使用了哪些值。当我看着它时,我看到了这样的东西
Function: someUintFunction1(uint256 maxTxAmount)
MethodID: 0xec28438a
[0]: 0000000000000000000000000000000000000000000000a2a15d09519be00000
Function: someUintFunction2(uint256 _minimumTokensBeforeSwap)
MethodID: 0xf0f165af
[0]: 000000000000000000000000000000000000000000000002b5e3af16b1880000
=
Function: someBoolFunction(bool _enabled)
MethodID: 0xc49b9a80
[0]: 0000000000000000000000000000000000000000000000000000000000000000
我猜00000000000000000000000000000000000000000000000000000000000000000000000000 bool是错误的?
但是我如何解码000000000000000000000000000000000000000000000000000000000000000000000000000000000和00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002B5E3AF16B18880000?
but how can I decode 0000000000000000000000000000000000000000000000a2a15d09519be00000 and 000000000000000000000000000000000000000000000002b5e3af16b1880000 to a readable value?
这些是 uint256
参数的值,转换为十六进制,使用大端显示(留下最大值)。
您可以手动将其转换为十进制,或者这里是使用 web3 JS 库的示例:
const Web3 = require('web3');
const web3 = new Web3();
const decimal = web3.eth.abi.decodeParameter('uint256', '0000000000000000000000000000000000000000000000a2a15d09519be00000');
console.log(decimal); // prints 3000000000000000000000
我一直在研究 solidity,我一直在通过 etherscan 研究以太坊主网上的类似项目。我试图了解合同的某些功能使用了哪些值。当我看着它时,我看到了这样的东西
Function: someUintFunction1(uint256 maxTxAmount)
MethodID: 0xec28438a
[0]: 0000000000000000000000000000000000000000000000a2a15d09519be00000
Function: someUintFunction2(uint256 _minimumTokensBeforeSwap)
MethodID: 0xf0f165af
[0]: 000000000000000000000000000000000000000000000002b5e3af16b1880000
=
Function: someBoolFunction(bool _enabled)
MethodID: 0xc49b9a80
[0]: 0000000000000000000000000000000000000000000000000000000000000000
我猜00000000000000000000000000000000000000000000000000000000000000000000000000 bool是错误的?
但是我如何解码000000000000000000000000000000000000000000000000000000000000000000000000000000000和00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002B5E3AF16B18880000?
but how can I decode 0000000000000000000000000000000000000000000000a2a15d09519be00000 and 000000000000000000000000000000000000000000000002b5e3af16b1880000 to a readable value?
这些是 uint256
参数的值,转换为十六进制,使用大端显示(留下最大值)。
您可以手动将其转换为十进制,或者这里是使用 web3 JS 库的示例:
const Web3 = require('web3');
const web3 = new Web3();
const decimal = web3.eth.abi.decodeParameter('uint256', '0000000000000000000000000000000000000000000000a2a15d09519be00000');
console.log(decimal); // prints 3000000000000000000000