3

I have a function which can rate ETH in USD. How can I find out the rate of ETH in USD in automatic mode?

Can this be done in Solidty? Or do I have to use a third-party language, for example, Javascript?

function setExchangeRate(uint value) onlyOwned {
    require(value > 0);


    ExchangeRateChanged(exchangeRate, value);
    exchangeRate = value;
  }
  • Hello Blanry, Could you please edit your post to make it clearer? When you say "This is can solidity...?" do you mean "Can this be done with Solidity? Or do I need a third-party language like Javascript?" I am confused by the fact that you say "I have a function which can rate ETH in USD" but then you ask how you can find out that rate... can you please clarify what you have already done, and what you are actually needing / asking? And what do you mean by "in automatic mode?" – Tesa Jul 30 '17 at 15:17
5

How find out the rate of ETH in USD in the contract?

To automatically get this data, rather than manually feeding it in by calling a function in the contract, you would need to use an oracle to get the real-world information into your contract. See these previous threads for an idea:

First interpretation: This is can solidty?

Yes, that code is Solidity, which is the language smart contracts are written in. You can't (currently) use native Javascript as a smart contract language. (There's no compiler that creates EVM bytecode from Javascript.)

Second interpretation: This can be done in Solidity?

Yes, see the threads I link to. Note that using an oracle isn't free. You will need to pay for the service.

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.