Scenario:
Imagine I create a crypto currency ZZZ (based on Ethereum blockchain) for buying/selling fruits.
There are two shops wanting to sell something:
- Apple shop, offering 5 kg of apples for sale, at price 10
ZZZper kg - Orange shop, offering 3 kg of oranges for sale, at price 15
ZZZper kg
There are three customers:
- Alice wants to buy 2 kg of apples from Apple shop
- Bob wants to buy 1.5 kg of apples from Apple shop
- Bob wants to buy 1 kg of oranges from Orange shop
- Cesar wants to buy 1.5 kg of oranges from Orange shop
After all four transactions complete there should be:
- 1.5 kg apples left in Apple shop
- 0.5 kg oranges left in Orange shop
ZZZ balance should be accordingly changed for each customer.
Questions:
- How can a shop record the available quantities in the blockchain?
- How can a shop transfer ownership of quantities of apples/oranges to the customers who bought them, in exchange for the
ZZZpaid? - I'm aware that the underlying blockchain tech will make sure no double spending of
ZZZcan occur, but how can I ensure no more apples/oranges are sold than there is available on stock? - Are there any sample projects which I could refer to to see how would solidity code look like for implementing such contracts where some value is partially transferred in exchange for the amount of the currency paid?