I want to exchange token for a commodity using smart contracts. I have deployed my token contract address in my private block chain network. How should I create another contract that exchanges a commodity using the transfer function from the deployed token contract?
ERC20 Tokens – How to Call Transfer Function from Another Contract
erc-20historytokens
Best Answer
You have a balance in your Token contract T. In order for your Commodity contract C to accept tokens and give the user the commodity in exchange, contract C would have to implement a function that accepts the tokens like follows:
Please take into consideration that the function above is not taking security measures under consideration.
For this to work, the token owner must first call approve on the token contract to allow contract C to use tokens on his behalf.