0

I'm using an oracle to get results from a custom api. The result is in string by default. I want to convert it to uint256, so that I can perform basic arithmetic functions.

Here's my code:

function __callback(bytes32 myid, string result) public{
       if (msg.sender != provable_cbAddress()) revert();
       uint256 points = uint(result); //Error here
       balanceOf[pointsAllowance[myid]] = points;
       remSupply = remSupply - points;
       emit LogPriceUpdated(points);
}

1

You are using OraclizeLib library correct? If yes, this library has defined parseInt method inside of it. Then your function can be used like this without problems:

function __callback(bytes32 myid, string result) public{
    if (msg.sender != provable_cbAddress()) revert();
    
    uint256 points = parseInt(result);
    balanceOf[pointsAllowance[myid]] = points;
    remSupply = remSupply - points;
    
    emit LogPriceUpdated(points);
}
| improve this answer | |

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.