【问题标题】:Solidity casting from "uint256" to "address"从“uint256”到“地址”的 Solidity 转换
【发布时间】:2022-01-06 01:23:53
【问题描述】:

我想知道如何将 uint256 数据类型转换为 Solidity 最新版本上的地址。

这是我正在开发的代码示例。

function setDetails(string memory _name) public onlyAuthCaller returns(address){
        uint256 tmpData = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp)));
        address batchNo = address(tmpData);

        detailsData.name = _name;

        batchDetails[batchNo] = detailsData;

        nextAction[batchNo] = 'NEXT';

        return batchNo;
}

在 Remix 上,我遇到 TypeError: Explicit type conversion not allowed from "uint256" to "address" on line:address batchNo = address(tmpData);

如果有人可以帮助我解决转换这些数据类型的错误。

问候

【问题讨论】:

    标签: type-conversion solidity


    【解决方案1】:

    可能是因为 uint256 太大,需要截断。

    取自docs

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 2022-08-06
      • 2020-02-04
      • 2018-08-20
      • 2021-11-17
      • 2018-11-25
      • 2022-08-19
      • 1970-01-01
      • 2019-12-21
      相关资源
      最近更新 更多