A msg.sender
can create multiple Struct Item
. What would be best way to store the Item
?
Currently I'm using
struct Item {
uint256 amt;
bool isActive;
address owner;
}
Item[] public items;
function createItem(uint amt) returns(uint a){
items.push(Item({
...
}))
return (items.length);
}
But createItem
returns a tx
hash as it's not mined yet.
Calling a items.length
after mining completes won't guarantee me the id
.
I also tried adding it in mapping but mapping don't accept Struct Arrays
Item[] public itemStack;
mapping(address => itemStack) public items; //TypeError: Name has to refer to a struct, enum or contract.
...
items[msg.sender].push(...)
mapping(address => Item[])
, right? For your first question, you pretty much have to log an event and check the transaction receipt for that event. (Last I checked, this was not straightforward in web3.js.) – user19510 Jan 19 '18 at 0:38