I have an issue with my oraclize. I need to call oraclaze for update exchange rate. If i call function updatePrice() manually - it's ok, global variable dollarCost is updating. But if I call updatePrice() automatically into the fallback function, dollarCost isn't updating.

How to call updatePrice() into the fallback function and get result in dollarCost before calc tokens (tokens = msg.value * dollarCost / 1000 / (10 ** 16);)?

pragma solidity ^0.4.11;

import 'https://github.com/oraclize/ethereum-api/oraclizeAPI.sol';

contract Test is usingOraclize {

uint public tokens;

uint public dollarCost;

function() payable {
    tokens = msg.value * dollarCost / 1000 / (10 ** 16);

function __callback(bytes32 myid, string result) {
    if (msg.sender != oraclize_cbAddress()) throw;
    dollarCost = parseInt(result, 3);

function updatePrice() public payable {

    if (oraclize_getPrice("URL") > this.balance) {
    else {
      oraclize_query("URL", "json(https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=USD).[0].price_usd");


Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.