将用户列表传递给构造函数中的Solidity智能合约

时间:2020-06-17 02:06:47

标签: ethereum solidity remix

我想创建一个保留用户列表的智能合约。用户具有姓名,电话,身份证等字段。 我想将用户结构列表作为参数传递给合同的构造函数。像这样:

contract SomeContract {

    struct User{
        address payable account;
        string fullName;
        uint id;
        uint256 birthdate ;
        string telephoneNumber;
        ...
    }

    User[] public users;

    constructor(User[] memory usersList) public payable{
        users = usersList;
    }
}

我已经在Remix中尝试过此操作,但是它显示一条错误消息,指出它需要使用ABIEnconderV2才能在构造函数中支持这些类型。 我尝试将pragma experimental ABIEnconderV2;添加到.sol文件中,但是Remix似乎也不支持它。

除了单独为每个字段传递数组之外,是否有任何“干净”的方式传递类似于对象的参数,并且这种方式不需要太多的参数?
如果没有,建议使用ABIEnconderV2,如何使用?

0 个答案:

没有答案