首页 > 解决方案 > How to get one value from struct of array in solidity?

问题描述

I want to get the value that is inside of struct in Solidity, but I have no idea how to get it.

pragma solidity >=0.4.21 <0.6.0;
contract PlaceList {

    struct hoge {
    uint id;
    address user;
  }

  hoge[] public hoges;

  constructor() public {
    admin = msg.sender;
  }

  function set(uint id) public {
    hoges.push(hoge(id, msg.sender));
  } 

  function getId() public view returns(uint) {
    return (hoges[0].id);
  } 
}

When I call getId, console command say this,

ƒ () {
              if (abiItemModel.isOfType('constructor')) {
                return target.executeMethod(abiItemModel, arguments, 'contract-deployment');
              }

              return targe…

Could you give me any advise how to get id by using solidity function, please?

标签: ethereumsoliditytruffle

解决方案


推荐阅读