provable-things / ethereum-api

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

Provide a constant method to getPrice() to know how much Oraclize is going to charge #35

Open jchittoda opened 6 years ago

jchittoda commented 6 years ago

I want to know how much is the fee oraclize is going to charge me before I send a transaction or Oraclize API. For example I want to know How much Oraclize would charge me for "URL" with specific gasLimit and gasPrice.

getPrice("URL", gasLimit, gasPrice) public constant

If I know this before making the actual request on platform. I can send that specific ETH into my transaction. Also we can charge that much of ETH from our customers.

D-Nice commented 6 years ago

Thanks for the suggestion @jchittoda

In regards to it, we don't think it's something critical (as you should already be able to do what you need with the implementation as-is), unless you can prove otherwise, so for now, will add this as a todo for a future update.

In regards to getting the price, you can do this already without sending any transaction on-chain, by explicitly using call, which should emulate what you're looking for with the constant specifier addition. Consider using the following call method in web3 over sendTransaction for this purpose: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcall

You will need to setup a helper from within your own contract, that calls getPrice, and then you call that helper using the above method. You may even be able to set the helper itself constant, getting the effect you want, without requiring an update from us.

jchittoda commented 6 years ago
     function getOraclizePrice() public constant returns (uint) {
          return oraclize_getPrice("URL", 80000);
     }

We have already been doing this. But during the solidity compilation it give below warning.

Warning: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.

The reason why we want this functionality is because at our platform user pay for the USD rate update in our Dapp, for this to happen, we need to fill in the MetaMask with the exact cost that Oraclize will charge our user for this call. Please get this method added, so that it stops giving compilation errors with 0.4.18 versions.

D-Nice commented 6 years ago

We agree this is a change we'll add in in a coming update, it's really not more than an annoyance at this point, in that you get that warning message from the compiler. The functionality is still the same.

chris-chr commented 5 years ago

I have the same issue with @jchittoda (the only difference is that I am using view instead of constant) but in compiler version 0.5.4 is a TypeError and I can't compile my contract.

TypeError: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.

Could you suggest any workaround until a fix is implemented?

D-Nice commented 5 years ago

We have a new connector we'll be deploying very soon, that has the view specifier applied to it.

Once we have it deployed, we'll in tandem update the oraclizeAPI interface.

You can already update that part of the oraclizeAPI @chris-chr to overcome the compilation error you've encountered.

Change

https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol#L42

to

function getPrice(string memory _datasource, uint _gasLimit) public view returns (uint _dsprice);

by adding the view specifier to that interface definition. That is the change we'll be doing ourselves to the api upon deployment.

Duncan-Brain commented 5 years ago

Hi,

I also would be interested in something to easily get the price of a datasource. I am not interested in a function though. Just a public variable on a library, or something I could call, would do for me. uint public randomPrice; uint public URLPrice; //et cetera... I can do my own math on gas limit and gas price .

Thanks for all the work you are doing.