有没有一种方法可以使用hardhat/console.sol
将字符串和bytes
变量记录在同一语句中?或者至少让它们打印在同一行上?
在Hardhat文档中,它显示您可以添加字符串参数:
console.log("Changing owner from %s to %s", currentOwner, newOwner)
但对于其他类型的变量,有办法做到这一点吗?
(string,bytes,bytes)
没有hardhat/console.sol
合约的log
函数过载,但有一个用于:
function log(string memory p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
也就是说,你可以这样使用它:
console.log("your format string %s %s", string(yourBytesVariable1), string(yourBytesVariable2));