I'facing problem when trying to put my sellPrice to 0.01 and my buyPrice equals to 0.02 in my smart contract after deployment. I intend to use setPrices function to set token price. So, I put within double quotes "10000000000000000" and "20000000000000000" because if I put without them, then it throws an exception.
Buy function:
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
uint amount = msg.value / buyPrice; // calculates the amount
_transfer(this, msg.sender, amount); // makes the transfers
}
On my web3 code:
$('#buy').click(function(){
Compra.buy({
gas: 300000,
from: web3.eth.coinbase,
value: 20000000000000000
},function(error,res){
console.log(res);
if(!error){
if(res.blockHash != $("#insTrans").html())
$("#loader").hide();
$("#insTrans").html("Block hash: " + res.blockHash)
}else{
$("#loader").hide();
console.log(error);
}
});
});
When buy() is successfull, I want to add to my wallet 0.000000000000000001 of my tokens and I want 1 token on my wallet. I mean 0.02 = 1 mytokens.
Someone can help me please? I am stuck here.