There's buyprice
on function buy
and sellprice
on function sell
. I would like to set up
1 ETH = 10000 (SYMBOL)
0.1 ETH = 1000 (SYMBOL)
0.01 ETH = 100 (SYMBOL)
0.001 ETH = 10 (SYMBOL)
How can I set a number on buyprice
and sellprice
? Even if i calculated it, it doesn't work at all
function buy() payable returns (uint amount) {
amount = msg.value / buyPrice; // calculates the amount
require(balanceOf[this] >= amount); // checks if it has enough to sell
balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
balanceOf[this] -= amount; // subtracts amount from seller's balance
Transfer(this, msg.sender, amount); // execute an event reflecting the change
return amount; // ends function and returns
}
function sell(uint amount) returns (uint revenue) {
require(balanceOf[msg.sender] >= amount); // checks if the sender has enough to sell
balanceOf[this] += amount; // adds the amount to owner's balance
balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
revenue = amount * sellPrice;
msg.sender.transfer(revenue); // sends ether to the seller: it's important to do this last to prevent recursion attacks
Transfer(msg.sender, this, amount); // executes an event reflecting on the change
return revenue; // ends function and returns
}