简体   繁体   中英

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.

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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