0

I am creating a smart contract, so inside that I have to pass the token in contract and the value of ether will be calculate on behalf of token price please help.

0

I think this is impossible, because the price is determined by traders on exchanges.

  • but if i have token price than? – Love Chawda Jan 23 at 7:00
  • u can't get data like this: uint public price = 'some.api/price', u have to pass price everytime when u need: function funcWhereYouNeedPrice(uint memory _price) onlyOwner external { "operations with _price" } – ffy Jan 23 at 7:48
  • but this is bad idea too, because u need to wait when transaction will be mined and price can be changed. so u will get not actual price. don't use this in financial operations – ffy Jan 23 at 8:01
  • so what is the correct way to buy token behalf of eth? because i want to make crypto to crypto smart contract where i need to sell erc20 token and on buyer side i need to claculate the price which i have to send to seller. – Love Chawda Jan 23 at 8:37
0

You can only set the price of a token during its initial distribution phase (e.g. the crowdsale, ICO, etc.). Once the tokens have been initially sold, and they are out in the real world, then the price is set by supply and demand; you have no control.

If you are currently writing your token distribution contract (this is separate to the ERC-20 contract itself), then you can set the price there. Have a look at these (OpenZeppelin) example contracts.

However, your question is a bit ambiguous. If you've already distributed your tokens, then you won't be able to set the price. If you've published the ERC-20 contract but haven't distributed the tokens, then you should still be able to run your distribution phase using your distribution contract.

  • i want to make crypto to crypto smart contract where i need to sell erc20 token and on buyer side i need to calculate the price which i have to send to seller can you please describe the calculation because i have a price of token. – Love Chawda Jan 23 at 9:51

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.