【问题标题】:TypeError: Return argument type tuple(int_const 23,bool,uint8[3] memory) is not convertible to expected type tuple(uint256,bool,uint256[3] memory)TypeError:返回参数类型元组(int_const 23,bool,uint8 [3]内存)不可转换为预期类型元组(uint256,bool,uint256 [3]内存)
【发布时间】:2022-11-22 15:25:38
【问题描述】:

//When I compile and deploy below code. It gives me no error

// SPDX-License-Identifier: MIT 
pragma solidity ^0.8.0; 
contract MultipleValues{
function returnValues() public pure returns (uint, bool, uint8[3] memory) {
    return (23, true, [1,2,3]);
}
}

//But when I change value from uint8[3] to uint[3] then it throws error

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MultipleValues{function returnValues() public pure returns (uint, bool, uint[3] memory) {
return (23, true, [1,2,3]);
}
}
//how to resolve this issue?
//Unexpected behaviour of array in solidity when returning a fixed size array

【问题讨论】:

    标签: arrays blockchain ethereum solidity smartcontracts


    【解决方案1】:

    这应该有效:

    contract MultipleValues{
        function returnValues() public pure returns (uint, bool, uint[3] memory) {
            uint[3] memory memoryArray;
            memoryArray[0]=1;
            memoryArray[1]=2;
            memoryArray[2]=3;
            return (23, true, memoryArray);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-13
      • 2022-09-23
      • 1970-01-01
      • 2017-09-05
      • 2020-09-03
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多