2

I create a smart contract successfully using Remix IDE , Metamask and Ropsten for testing.

I want to sell some tokens using Sell function, so I specified the value "20" for Sell function ,my initial balance was 600 after that I checked the balanceOf , the new value is 580,but my Ether Balance on Metamask didn't change. My sell function code is :

 function sell(uint amount)public returns (uint revenue){
        require(balanceOf[msg.sender] >= amount);        
        balanceOf[this] += amount;                      
        balanceOf[msg.sender] -= amount;                  
        revenue = amount / sellPrice;                    
        msg.sender.transfer(revenue);                    
        emit Transfer(msg.sender, this, amount);         
        result = amount;
        return revenue;                                 
    }
0

I'm guessing the function returns 0 as revenue. That's quite typical for when trying to calculate floating point numbers.

You can read more about how to do division for example here: How can I perform float type division in solidity?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.