solidity代码如下:
function toBytes() public view returns (bytes memory) { bytes32 by32 = hex"5569a35483840767334b19c6f28d1347dad8ec4521859a1742d2175898489752"; bytes memory bym1 = bytes(by32);//此处直接转换会报错 bytes memory bym2 = abi.encodePacked(by32);//此处为正确的转换方式 return abi.encodePacked(bym2); }
报错内容如下:
上述solidity函数在remix中输出结果如下(和by32的内容一模一样):
标签:类型转换,solidity,bytes,bytes32,报错,memory,by32 From: https://www.cnblogs.com/forkroad/p/16995265.html