to be
a problem slover

solidity dynamic error msg

pragma solidity 0.6.6;

contract DynamicErrorMsg{

    function DynamicErrorMsgTest(uint uintInput, string calldata strInput) external {
        require(false,string(abi.encodePacked("something get wrong: ",uintToString(uintInput), "," , strInput)));
    }

    function uintToString(uint v) pure internal returns (string memory) {
        // max uint 115792089237316195423570985008687907853269984665640564039457584007913129639935 has 78 digits
        uint maxlength = 78;
        bytes memory reversed = new bytes(maxlength);
        uint i = 0;
        while (v != 0) {
            uint remainder = v % 10;
            v = v / 10;
            reversed[i++] = byte(uint8(48 + remainder));
        }
        bytes memory s = new bytes(i);
        for (uint j = 0; j < i; j++) {
            s[j] = reversed[i - j - 1];
        }
        string memory str = string(s); 
        return str;
    }
}
赞(3) 打赏
欢迎转载,注明出处:刘世明的博客 » solidity dynamic error msg

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏