0

I am working on making my own crypto currency. In the tutorial https://www.ethereum.org/token there is a section titled "AUTOMATIC SELLING AND BUYING" which gives an example with the following function as well as a buy and sell function.

uint256 public sellPrice;
uint256 public buyPrice;

function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
    sellPrice = newSellPrice;
    buyPrice = newBuyPrice;
}

This is great, but can someone tell me how I would actually calculate the buy and sell price? Could it be something like:

C = Current Price of Ether USD

A = Total ether

H = Total Number of My Coins

C * A / H = Buy Price

However, the problem with the above is updating the current price of Ether. That would cost me gas every time..

1
  • I am working on making my own crypto currency

You are not creating a cryptocurrency, but a token (or a coin) based on a cryptocurrency blockchain.

  • However, the problem with the above is updating the current price of Ether. That would cost me gas every time..

Yes, and you have no other option. Something very important to understand about smart contracts (but it seems you already got it) is that they are "dead" pieces of code and can only be triggered from an external call (or from an other contract). As a consequence, if something on your contract is dynamic and depends on something that is "external" to the contract, you need to update it "manually", or you can set up, for example, a nodejs server with web3js that updates the value in the contract automatically.

And yes, this costs money.

Note: A value of a token is, en general, not indicated by the contract itself, but from market exchanges. For example, you create a token, 1 ether is worth 1 token. But 1 ether it not always worth 1 USD (this values are example, not real values). So as a consequence, the value of the token is determined by the value of ether.

Hope I helped you :)

| improve this answer | |
  • Thanks for your answer. Any insight into how I’d value my token? Why set 1 token arbitrarily to equal 1 ether? – pizzarob Jan 16 '18 at 3:14
  • The value I provided are just for examples. you can set the value of your token to what you want (0.1, 0.0000001ether ...) For a propoer solution about your goal, I am not good enough to implement a good one – Florian Castelain Jan 16 '18 at 3:18

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.