provable-things / ethereum-api

Provable API for Ethereum smart contracts
https://docs.provable.xyz/#ethereum
MIT License
801 stars 428 forks source link

What the actual price for the URL request? #38

Closed akucheruk-vareger closed 6 years ago

akucheruk-vareger commented 6 years ago

Hi,

From the manual we can learn that the base price for the URL request is 0.01$ But I've got 0.0040336 Ether (for this days) for this contact code:

  function getTokens(address beneficiary) public payable {
        require(beneficiary != address(0));
        uint256 price =  oraclize_getPrice("URL");
        if (price > msg.value) {
            LogNewOraclizeQuery("Oraclize query was NOT sent");
        } else {
            LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer..");
            // TODO creating query with address parameter
            bytes32 queryId =
                oraclize_query("URL", "xml(https://example.com/balances).tokenBalance");
            tokenHolders[queryId] = beneficiary;
        }
    }

    function __callback(bytes32 myid, string result) public{
        require(msg.sender == oraclize_cbAddress());

        uint tokenBalance = parseInt(result, 2);
        address beneficiary = tokenHolders[myid];

        token.mint(beneficiary, tokenBalance);
    }

https://ropsten.etherscan.io/tx/0x8c2168ce411f175b999ec362f8f9ac06a42b84175a46dc796448dfa3c6833a55

0.0040336 Ether - 0.004 (200 000 gas limit * 20Gwei) = 0.0000366 Ether = 0.03$

So, what the actual price for the URL request and how to know it?

Thank you.

bertani commented 6 years ago

The ETHUSD price is not updated that often on testnets, so it might be a bit off, on mainnet we try to keep it updated to reflect the market changes. If you want to check in advance the price, you can use the oraclize_getPrice(datasource, callbackgas) helper method. I hope this helps!

akucheruk-vareger commented 6 years ago

Got it. Thank you!