0

I sell goods for tokens. And I would like to make a wallet of goods for each user. So that he sees the amount of each product that he bought. Can I realize this in solidity? For example: through mapping? thanks

edit

At the moment, I can exchange my goods for tokens. But for each product I have a separate wallet. for example, for product A msg.sender => amount, and for product B msg.sender => amount. I want to do msg.sender => goods (A or B or other) => amount.

2
  • Standard like ERC20 commonly represent tokens, but they basically are assets. So basically, you can consider your goods like tokens and exchange them like you would for tokens. – Florian Castelain Feb 11 '20 at 12:01
  • @Florian Castelian thanks for answer. At the moment, I can exchange my goods for tokens. But for each product I have a separate wallet. for example, for product A msg.sender => amount, and for product B msg.sender => amount. I want to do msg.sender => goods (A or B or other) => amount. Can i implement this? – modernToking Feb 12 '20 at 5:01
0

For your question in the comments of question, here is what you could do (tell me if I understood correctly):

 mapping(address => goods) private goodsList;

    struct goods {
        uint Apples; 
        uint Bananas;
    }

You can then access them by doing something like:

uint myBananes = goodsList[ADDRESS].Bananas;
unit myApples = goodsList[ADDRESS].Apples;

I don't know how you code to exchange tokens for goods looks like. But this should give you a good starting point.

Documentation for structs

2
  • Thank you if I don’t know the quantity of goods (in your example apples and bananas). I add products and sell. At the moment, I implemented so struct WalletOfGood { uint amountOfgood; } mapping (address => mapping (string => WalletOfGood)) walletOfGoods; `` walletOfGoods [_address] [_ nameOfgood] .amountOfgood. can I just contact the address without indicating the name of the product to get their name and quantity? – modernToking Feb 12 '20 at 8:47
  • @malysh You could just get the mapping like walletOfGoods[address]. I am not sure though – Florian Castelain Feb 12 '20 at 9:01

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