codecamp

ABI 编码和解码函数

  • abi.decode(bytes memory encodedData, (...)) returns (...): ABI 解码给定的数据,而类型在括号中作为第二个参数给出。例子:(uint a, uint[2] memory b, bytes memory c) = abi.decode(data, (uint, uint[2], bytes))
  • abi.encode(...) returns (bytes memory): ABI 编码给定的参数
  • abi.encodePacked(...) returns (bytes memory):对给定参数执行打包编码。请注意,打包编码可能不明确!
  • abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory): ABI 从第二个开始对给定的参数进行编码,并将给定的四字节选择器放在前面
  • abi.encodeWithSignature(string memory signature, ...) returns (bytes memory): 相当于abi.encodeWithSelector(bytes4(keccak256(bytes(signature))), ...)
  • abi.encodeCall(function functionPointer, (...)) returns (bytes memory)functionPointer: ABI使用元组中的参数对调用进行编码。执行完整的类型检查,确保类型与函数签名匹配。结果等于abi.encodeWithSelector(functionPointer.selector, (...))

笔记

这些编码函数可用于为外部函数调用制作数据,而无需实际调用外部函数。此外,它是一种计算结构化数据散列的方法(尽管请注意,可以使用不同的函数参数类型来制造“散列冲突”)。keccak256(abi.encodePacked(a, b))

有关编码的详细信息,请参阅有关ABI和 紧密打包编码的文档。


块和事务属性
字节成员
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }