# Is struct data returned from web3 guaranteed to be in the correct order?

I have this solidity struct

``````struct Prices {
uint sell_price;        // wei
uint target_price;      // primary
uint penalty_price;     // wei
}
Prices public prices
``````

In truffle when I do `contract.prices()` I retrieve an array `[sell_price, target_price, penalty_price]` , the order which they are listed in the struct. I wanted to know if this order is guaranteed?

Yes

The getter function that Solidity generates uses the order listed in the struct. Solidity would generate a function of the following form:

``````function prices() constant returns (uint sell_price, uint target_price, uint penalty_price) {
sell_price = prices.sell_price;
target_price = prices.target_price;
penalty_price = prices.penalty_price;
}
``````

Here's the ABI and see that the `outputs` have a specific order:

``````[
{
"constant": true,
"inputs": [],
"name": "prices",
"outputs": [
{
"name": "sell_price",
"type": "uint256"
},
{
"name": "target_price",
"type": "uint256"
},
{
"name": "penalty_price",
"type": "uint256"
}
],
"payable": false,
"type": "function"
}
]
``````

``````contract Complex {
struct Data {
uint a;
bytes3 b;
mapping (uint => uint) map;
}
mapping (uint => mapping(bool => Data[])) public data;
}
``````

It will generate a function of the following form:

``````function data(uint arg1, bool arg2, uint arg3) returns (uint a, bytes3 b) {
a = data[arg1][arg2][arg3].a;
b = data[arg1][arg2][arg3].b;
}
``````

Note that the mapping in the struct is omitted because there is no good way to provide the key for the mapping.

Yes.

The ABI is a collection of fixed-length arguments in a specific order. The elements will be reliably/consistently ordered.

Hope it helps.