1

Suppose i have a struct called product,

struct product{ uint prodcode; string prodname; uint quantity; uint price }

and if i have 1000 units(quantity) of a product p1 and i want to send 200 units of p1 to another person's address. So the ownership of the 200 units of p1 will belong to that person but the ownership of the remaining 800 units should still be mine.

Is there a way to implement this?

1 Answer 1

1

Yes of course.

You can create a mapping of addresses to a uint256 which will hold the balances of each address in a single product. then make another mapping holding such mappings. something like this

mapping(bytes32 => mapping(address => uint256)) public products;

getBalance(bytes32 productID, address userAddress) public returns (uint256){
    return products[productID][userAddress]
}

Another thing is: all of these concepts are explored with the ERC20 and similar tokens with stake contracts, where you can create tokens, transfer them to others thus delegating ownership of some tokens to other addresses and block those tokens if you want. to adapt to your concept, you can create a new token for each product you have and use that token as a means for ownership delegation.

1
  • Thank you so much for this solution
    – Alan Babu
    May 13, 2021 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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