I have the following struct inside my vyper file:

races: public({
  start: timestamp,
  end: timestamp,
  racersBetHash: bytes32[address],
  racersBetAmount: wei_value[address]

Then I call this function:

def registerRacerBet(_tokenHash: bytes32, _raceID: int128) -> bool:
  self.races[_raceID].racersBetAmount[msg.sender] = msg.value
  self.races[_raceID].racersBetHash[msg.sender] = _tokenHash

  log.NewUserBet(_raceID, msg.sender,
  return True

Inside my truffle test, I'm able to test the correctness of the log, so I'm sure that the struct is properly defined but, if I try to read the value of the struct for the two mapping fiels the call turns back zero value.

I have no problems to read start and end

const currentHashBet = await instance.races__racersBetHash.call(0, '0xf17f52151ebef6c7334fad080c5704d77216b732');

currentHashBet: 0x0000000000000000000000000000000000000000000000000000000000000000


1 Answer 1


You have a few options, the first one being to write your own function that returns an struct correctly.

In Solidity this could look like

pragma solidity ^0.4.13;

contract Project
struct Person {
    address addr;
    uint funds;

Person[] people;

function getPeople(uint[] indexes)
    returns (address[], uint[])
    address[] memory addrs = new address[](indexes.length);
    uint[]    memory funds = new uint[](indexes.length);

    for (uint i = 0; i < indexes.length; i++) {
        Person storage person = people[indexes[i]];
        addrs[i] = person.addr;
        funds[i] = person.funds;

    return (addrs, funds);

I think your problem is that you aren't adding the index of the mapping item. See public-struct-array variable getter.

Let me know if you have any questions, also you might have reversed the order of index and address.

const currentHashBet = await instance.races__racersBetHash.call( '0xf17f52151ebef6c7334fad080c5704d77216b732',0);

If I remember correctly, 0x000 is the null value for addresses, doesn't exist.

  • Hi, I have tryed reverting the parameter, but the transaction was reverted. Also if I look into the artifact the function has this "signature" "inputs": [ { "type": "int128", "name": "arg0" }, { "type": "address", "name": "arg1" } ], as you can read the firts input is the index and the second is the address. I don't undertand the utility of this getter if I have to write a custom one.
    – magiceddy
    Commented Sep 28, 2018 at 7:32
  • I think you might have to write a custom getter as you we cannot return dynamic array directly in Solidity due to EVM limitations, I suspect this is the same in Vyper. See Dynamic Array and Dynamic Arrays
    – GrandFleet
    Commented Sep 29, 2018 at 15:15
  • Ironically, I ran into the same problem that you were having, it seems that arrays in structs can't be returned with public getters, you have to write a getter to obtain the array inside the struct.
    – GrandFleet
    Commented Sep 29, 2018 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.