Q:

Sending token from and to smart contract

I created smart contract where I send token from contract to senders wallet. 
I also want contract to receive tokens and send back ETH. In what way can I find out how much tokens sender sends to smart contract?

A:

When writing an ERC20 smart contract you have to write the transfer() function. The parameters are 

_to destination of tokens
_value value of tokens sent

This is the implementation part of the SingularDTV contracts
/*
 *  Read and write storage functions
 */
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
function transfer(address _to, uint256 _value) returns (bool success) {
    if (balances[msg.sender] >= _value && _value > 0) {
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        Transfer(msg.sender, _to, _value);
        return true;
    }
    else {
        return false;
    }
}

The user has to call your transfer() function. You can add the rest of the logic in the function.

