I am new to blockchain. I am trying to implement a dapp project in my college curriculum. I am trying to implement seller-buyer smart contract on private ethereum node(using solidity, geth console, mist browser). Please help.
Problems that I am facing:
Once the seller contract is executed after entering all the values. I want to capture the updated product quantity. Ex: The seller is selling 10 apples and each apple costs an ether. Once the buyer transfers 1 ether to seller account then the product quantity should be updated to 9 (it means the seller sold 1 apple) based on the ether sent by the buyer the product quantity should get updated in read from contract.
How to display this updated product quantity
How to show that the buyer received the product
I created 2 contracts: buyer and seller. I created 2 accounts: buyer account and seller account.
Buyer contract: I am writing/reading from contract: buyer name, buyer address
seller contract: I am writing to the contract: seller name, seller address, product description, perunitcost.
Here is the code:
pragma solidity ^0.4.15;
contract Seller {
uint public value;
address public seller;
string public sellername;
string public selleraddress;
string public productdescription;
uint public perunitcost;
uint public productquantity;
uint public updatedproductquantity;
mapping (address => uint) public balances;
function Seller(string tokensellername,string tokenselleraddress, string tokenproductdescription, uint tokenproductquantity,uint tokenperunitcost) public {
sellername = tokensellername;
selleraddress = tokenselleraddress;
productdescription = tokenproductdescription;
productquantity = tokenproductquantity;
perunitcost = tokenperunitcost;
}
function confirmPurchase(address _seller) payable {
uint itemstoBuy = value / msg.value;
// balances[_seller] holds the number of carrots to sell
require(balances[_seller] >= itemstoBuy);
balances[_seller] -= itemstoBuy;
balances[msg.sender] += itemstoBuy;
_seller.transfer(msg.value); //transfer the ether to the seller
//display how much product quantity in left: show this on read from contract
updatedproductquantity = balances[_seller];
}
}