I've created a function which gets a struct which contains int+struct.
Now when I want to test it, what data should I send for example on Remix:
here's the code, got from another SO question on – How to send an array of structs as arguments
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;
contract ExchangeContract {
enum CurrencyType { USD, TWOKEY, BTC, ETH, DAI, USDT, TUSD, EUR, JPY, GBP}
mapping(uint256 => CurrencyPrice) public priceByCurrencyType;
struct Price{
uint price;
uint decimals;
}
struct CurrencyPrice{
uint currencyInt;
Price price;
}
function updatePrices(CurrencyPrice[] memory _array) public {
for(uint i=0; i<_array.length; i++){
priceByCurrencyType[_array[0].currencyInt].price=_array[i].price;
}
}
}
Now, I want to interact with that function from Remix – is it possible?
Best Answer
The struct used as the parameter type in your
updatePrices
has a particularity, it contains a member which type is another struct. We will come back to that later, for now let's look how it goes with a "simple" struct.You can see it's rather simple. On Remix, if you want to call
add
, it's simple too. You just create an array, like you would for any other type, and then add "sub-arrays" which will represent each struct.Here's an example :
You are adding two structs. The first one contains
1
and2
, which will be respectively assigned to thea
andb
members of the struct, and same thing for the second one which has3
and4
.Now, back to your contract.
Logically, we would call
updatePrices
with the following input[[5,[2,2]]]
. It's an array of length1
, with5
being thecurrencyInt
member and[2,2]
the corresponding values for thePrice
struct.It's not possible on remix.ethereum.org for now, it won't work.
However, it's implemented on alpha remix, and if you used the input above, it will work fine.
Regarding your contract itself
I think there is an error on this line
You probably intended to do
_array[i]
.