0

I have a situation where I send 1$ worth of ether to my smart contract..

Now, how do I validate the same on solidity? How do I make sure that the user is sending 1$ worth of ether at any given time.

I mean to say, how can I make sure msg.value in solidity is actually equal to 1$ worth of fiat from solidity.

Edit: I do know, an oracle can be used as a data source. But is there an oracle that provides an api like poloinex.

Step 1: I call the https://poloniex.com/support/api/ and obtain ether - fiat value

Step 2: I send a transaction to a contract using the previously obtained value: contract.method.aPayableMethod().sendTransaction({ value: toWei('value from poloinex') })

Step 3: In my payable function inside solidity, how do I make sure, that that the msg.value is always equal to 1$.

  • Can you provide more details? Because if the user sends 1 ether (lets say its worth 1$), then the contract will receive 1 ether and you do what ever you need to do with this. – Florian Castelain Jan 15 '18 at 5:52
  • I want to validate, if 1 ether is currently equal to 1$. – InfinitePrime Jan 15 '18 at 7:19
  • Hi there. "Price in USD" is almost meaningless IMO :-) Price according to who? Which exchange or market are you going to use for your valuation? Is that the same market that your contract's users will be using? What if the price in your chosen market changes while you're making the API/oracle call? What if the price changes while your user is waiting for their transaction to be mined? – Richard Horrocks Jan 15 '18 at 11:36
  • Yes, Il be using coinbase exchange rate api. Wont these api's offer a 24hour average price? And do you think, I should just check for msg.value and if it exists, just continue. – InfinitePrime Jan 15 '18 at 12:09
2

Please take a look at the FiatContract. It is a donation driven contract that updates fiat values every hour.

  • But, it's too late. I ended up accepting ETH. – InfinitePrime Jun 28 '18 at 6:20
0

You'd need to use something like an oracle which could provide that information on-chain, but you need to trust that the oracle will return valid data at all times.

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.