【问题标题】:TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[3] memory to uint256[] memory requestedTypeError:函数调用中的参数类型无效。从 uint256[3] 内存到 uint256[] 内存请求的隐式转换无效
【发布时间】:2022-08-13 03:20:43
【问题描述】:

所以我在使用铸造厂.所以我有一个函数,它以数组类型的 uint256 作为参数。但是当我做测试时,它显示了一个隐性错误。

TypeError:函数调用中的参数类型无效。从 uint256[3] 内存到 uint256[] 内存请求的隐式转换无效。

contract Test {
    uint256[] private threshold = [1000, 2000, 3000];

    function setThreshold(uint256[] memory _threshold) public onlyOwner {       
        threshold = _threshold;
    }
}

有谁知道如何解决这个问题?

    标签: solidity smartcontracts implicit-conversion


    【解决方案1】:

    您调用 setThreshold 函数的脚本中可能存在错误,或者您的测试中有错误。

    为了更简单的检查,我对您的代码做了一些小改动

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    
    contract Test {
        uint256[] public threshold = [21000, 2000, 3000];
    
        function setThreshold(uint256[] memory _threshold) public {
            threshold = _threshold;
        }
    }
    

    这是我的部署脚本: 从布朗尼进口测试,帐户

    def main():
        check = Test.deploy({"from": accounts[0]})
        print(check.threshold(0))
        check.setThreshold([1000, 1000, 1000], {"from": accounts[0]})
        print(check.threshold(0))
    

    这是一个输出:

    运行“脚本/deploy.py::main”... 交易发送:0x63fba19e52cb9064c43d25f76b43151ddc5cbf4ba55ca30f469322eeabd824bf Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 0 Test.constructor 确认 Block: 1 Gas used: 257509 (2.15%) 测试部署在:0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc8721000发送的交易:0xe48cd3a8231fdc4e246b5e93aa1fc4544dabce6ef4f19bfd65fb8044d42ad9db Gas 价格:0.0 gwei Gas 限制:12000000 Nonce:1 Test.setThreshold 确认 Block: 2 Gas used: 39640 (0.33%)1000正在终止本地 RPC 客户端...

    【讨论】:

      猜你喜欢
      • 2022-11-22
      • 1970-01-01
      • 2021-12-31
      • 2022-08-19
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2018-08-20
      相关资源
      最近更新 更多