简体   繁体   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;
    }
}

I am trying to pass values to struct variable through constructor But I am getting this following error.我试图通过构造函数将值传递给结构变量但是我收到以下错误。

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

I tried running the same code and it worked just fine.我尝试运行相同的代码,但效果很好。

Constructor runs only once and that is at the time of deployment.构造函数仅运行一次,即在部署时运行。 Since you are passing the values to constructor, you should pass the values at the time of deployment.由于您将值传递给构造函数,因此您应该在部署时传递这些值。

My reputation does not seem to allow me to upload the image.我的声誉似乎不允许我上传图像。 Please go through the link below.请通过以下链接拨打 go。

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

So guys, I resolved the error.伙计们,我解决了这个错误。 It wasn't actually an error.这实际上不是错误。 It was just a silly mistake that I made as a beginner.这只是我作为初学者犯的一个愚蠢的错误。

SOLUTION: - I wasn't actually passing values to constructor initially.解决方案: -我实际上并没有最初将值传递给构造函数。 Actually when we add constructor in our contract we basically get a input section with our deploy button automatically (even before actually deploying).实际上,当我们在合约中添加构造函数时,我们基本上会自动获得一个带有部署按钮的输入部分(甚至在实际部署之前)。 which have to be used to pass values before deploying our contract.在部署我们的合约之前必须使用它来传递值。

在此处输入图像描述

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

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