I'm building a token contract with a sell and buy function. User should be able to buy my token not only for eth but also for another token, that I define. Therefore I need the balance mapping of the external token in my contract. I've tried:
contract externalToken {
function transfer(address receiver, uint amount){ }
mapping (address => uint256) public balanceOf; }
and in my buy function:
...
amount = externalToken.balanceOf[msg.sender] / buyPrice;
...
But it shows this error:
Indexed expression has to be a type, mapping or array (is function (address) returns (uint256))
if (exchangeToken.balanceOf[msg.sender] < buyPrice) throw;
How to do that right?
Best Answer
See How do I get a refund for the amount I paid in excess of 1 ether to 100 The DAO tokens for a working example.
There is an
ExtraBalToken
contract with abalanceOf(...)
method:To access the
ExtraBalToken.balanceOf(...)
fromWithdrawDAO
: