# web3-无ABI合约交互 **Published by:** [Hogen](https://paragraph.com/@hogen/) **Published on:** 2022-06-30 **URL:** https://paragraph.com/@hogen/web3-abi ## Content 格式 InputData = 0x 60fe47b1 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000002 InputData = 0x + 4字节函数选择器 + 各32字节Data encode 函数选择器bytes4(sha3(“set(uint256)”)) == 0x60fe47b1 def getFuncHex(funcData): k = sha3.keccak_256() k.update(funcData.encode('utf-8')) return k.hexdigest()[:8] encode Data参数转16进制 [address不用转] web3.toHex(value) 前面补0,填充满64位\32字节(bytes32) [string除外]// python def to_64(hex): zero = '' hex = hex[2:] //去除hex的0x zcount = 64-len(hex) for i in range(zcount): zero += '0' return zero+hex 每个参数拼接到一起实例:def encodeInputData(funcName,inputArr): funcName = '' for item in inputArr: ---- funcData各种拼接----- // funcData拼接后 = 'ChangeNum(uint256,address)' funcHex = getFuncHex(funcData) def getFuncHex(funcData): k = sha3.keccak_256() k.update(funcData.encode('utf-8')) return k.hexdigest()[:8] funcName = 'testEasyInput' inputArr = [ {'type':'uint256','value':11}, # {'type':'string','value':'grewgrewgreggreggregreqweeeeeeee'}, # {'type':'address','value':myAddress}, {'type':'uint256','value':22},] encodeInputData(funcName,inputArr) ## Publication Information - [Hogen](https://paragraph.com/@hogen/): Publication homepage - [All Posts](https://paragraph.com/@hogen/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@hogen): Subscribe to updates