I am currently implementing a private Ethereum Blockchain. I have also created a custom ERC20 Token smart contract. I want to know how to use this custom token instead of ether for another smart contract related to buying and selling products? The purpose is that once buyer wants to buy some item he should be able to make a payment in terms of custom toke say my_token and once the transaction is mined the desired number of my_tokens should be added to seller's account and same number should be deleted from the buyer's account.
Achieving this should be pretty straightforward. You have your token contract at address 0x0A with all the balance assigned to you, the issuer.
Say someone buys tokens from you, so you transfer them to Account 0x0B.
Now, 0x0B wants to interact with contract X that has a function that accepts your tokens instead of ether.
The function from this contract would first get an instance of your token contract by doing
Token yourToken = Token(0x0A);
Now that it has a reference to your token contract, it would have to transfer tokens from the buyer balance to its own balance by using the
transferFrom(buyer, this, someAmount); function.
If that call succeeds, then you can safely assume that the tokens are now in possession of the marketplace contract.
Notice that for the above to work, first, the buyer must approve that allowance to the marketplace contract to allow it to subtract tokens from the buyer.