繁体   English   中英

在solidity中使用构造函数时出现大数错误

[英]Error of Big number while using constructer in solidity

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.12;

struct account{
        string _name;
        uint _acc_id;
        uint balance;
    }     

contract My_acc{
    account public person;

    constructor(string memory name, uint acc_id, uint _balance){
        person._name = name;
        person._acc_id = acc_id;
        person.balance = _balance;
    }
}

我试图通过构造函数将值传递给结构变量但是我收到以下错误。

creation of My_acc errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.5.0)

我尝试运行相同的代码,但效果很好。

构造函数仅运行一次,即在部署时运行。 由于您将值传递给构造函数,因此您应该在部署时传递这些值。

我的声誉似乎不允许我上传图像。 请通过以下链接拨打 go。

https://i.stack.imgur.com/AFBWd.png

伙计们,我解决了这个错误。 这实际上不是错误。 这只是我作为初学者犯的一个愚蠢的错误。

解决方案: -我实际上并没有最初将值传递给构造函数。 实际上,当我们在合约中添加构造函数时,我们基本上会自动获得一个带有部署按钮的输入部分(甚至在实际部署之前)。 在部署我们的合约之前必须使用它来传递值。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM