5 怎么计算合约的 function hash

'filled(bytes32)': '0x288cdc91',
    'getOrderQueueInfo(address,address,bool)': '0x22f42f6b',
    'transfer(address,uint256)': '0xa9059cbb',
    'getOrderInfo(bytes32,bytes32,bool)': '0xb7f92b4a',
    'takeOrder()': '0xefe29415',
    'approve()': '0x095ea7b3',
    'allowance': '0xdd62ed3e',
    'cancelOrder(bytes32,bytes32)': '0xa47d9d33',
    'cancelOrder2(bytes32,bytes32)': '0xa18d42d3',
    'orderFlag(bytes32)': '0xf8a8db0e',
    'sellQueue(bytes32)': '0xf875a998',
    'getOrderDepth(bytes32)': '0x3e8c0c4c',
    'getBQODHash()': '0xefe331cf',
    'getBQHash()': '0x30d598ed',
    'getDecimals()': '0x313ce567',
    'getTokenBalance()': '0x70a08231',
    'getConfigData()': '0xfeee047e',
    'getConfigSignature()': '0x0b973ca2',
    'orderFlags(bytes32 od_hash)': '0x76356e86',
    'configurations(string key)': '0x1214dd58',
请先 登录 后评论

最佳答案 2021-07-28 15:16

这个叫函数选择器(参考文档:应用二进制接口说明 函数选择器 — Solidity中文文档 ): 对函数签名字符串进行sha3(keccak256)哈希运算之后,取前4个字节.

例如set(uint256) 的函数选择器是:

bytes4(sha3("set(uint256)")) == 0x60fe47b1

使用 web3.js 可以获得函数选择器的编码值,文档: web3.eth.abi — web3.js 中文文档

// 参数是字符串
web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
> '0x24ee0097'

如果是在 solidity 里面, 则函数有一个 .selector ABI 函数选择器 . 参考文档: 函数类型 — Solidity中文文档

请先 登录 后评论

其它 0 个回答