0

I have a Solidity contract using Oraclize. I use it to generate a random number between 0-100.

My problem is that I get a string in the result response and would like to compare with a uint.

As soon as I try to add this line of code to convert the result to a uint, the __callback function never gets executed as it expend too much gas.

playerDieResult[myid] = parseInt(result);

If I remove this line, my __callback function gets executed and I see the result stored in a memory variable as a string correctly.

My problem is that I don't have a way to compare that randomly generated number with another number.

3
  • Hello and welcome :) they're no native way of converting an string to an uint in solidity but with custom code you can do about anything. Maybe this will work for you? ethereum.stackexchange.com/questions/10932/…
    – Foxxxey
    Commented Oct 3, 2021 at 14:15
  • Thank you Foxxxey. This is the method I'm following :) Was wondering if there was a more efficient way to do it but haven't been able to find any.
    – victor
    Commented Oct 3, 2021 at 15:59
  • Are you sure parseInt works correctly? My guess is that it has a bug that causes the failure.
    – Ismael
    Commented Oct 3, 2021 at 21:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.