You probably shouldn't use this for anything important. since it piggy backs on the Oraclize pricing internals it could suddenly change if Oraclize changes their pricing model.
Availabe @ 0x1c68f4f35ac5239650333d291e6ce7f841149937
This oracle uses the Oraclize it connector contract to derive the price of
Ether. The Oraclize it service charges 1 cent per URL query. To make it easy
to pay the right amount for queries, the contract provides a helper function
getPrice(..)
which returns the appropriate value in wei that should be sent
for a given query. By checking this value, we can compute what the price of
ether is according to the Oraclize it service.
The contract presents three functions:
WEI() constant returns (uint)
returns 1 USD in WEI
USD() constant returns (uint)
returns 1 ETH in US cents.
You can use the following interface in your solidity code.
contract USDOracle {
function WEI() constant returns (uint);
function USD() constant returns (uint);
}
For example. if you wanted to charge $10 for something.
contract SellStuff {
USDOracle oracle = USDOracle(0x1c68f4f35ac5239650333d291e6ce7f841149937);
uint constant USD_IN_CENTS = 100;
function buyStuff() {
if (msg.value < 10 * USD_IN_CENTS * oracle.WEI()) throw;
... // sell them stuff
}
}
This can be used to view the contract using the Ethereum Wallet application or really any other Ethereum thing that needs an ABI to interact with a contract.
[
{
"constant": true,
"inputs": [],
"name": "USD",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "WEI",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"type": "function"
},
{
"inputs": [],
"type": "constructor"
}
]
Here's a screenshot from my view of this contract using the Wallet Application.
This was compiled with solidity 0.2.1
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.2.1-91a6b35f/Release-Darwin/unknown/int linked to libethereum-1.1.1-3d460fbb/Release-Darwin/unknown/int
Compiled with the --optimize
flag enabled.
$ solc --optimize contracts/USDOracle.sol --bin --bin-runtime
======= USDOracle =======
Binary:
606060405260008054600160a060020a031916731d11e5eae3112dbd44f99266872ff1d07c77dce8179055610338806100386000396000f3606060405260e060020a6000350463104d5fdd81146100475780631bf6c21b1461010c578063531b97d7146101195780638129fc1c146101f8578063b845c9a2146102ff575b005b61030c600080546040805160e060020a6338cc483102815290518392600160a060020a0316916338cc4831916004828101926020929190829003018187876161da5a03f11561000257505060408051805160e260020a630bbceb3302825262030d406024830152600482018390526003604483015260ea60020a621554930260648301529151919350600160a060020a0384169250632ef3accc916084828101926020929190829003018188876161da5a03f115610002575050604051519250505090565b61030c600061032761011d565b61030c5b6000600060006000600060009054906101000a9004600160a060020a0316600160a060020a03166338cc48316040518160e060020a0281526004018090506020604051808303816000876161da5a03f11561000257505060408051805160e260020a630bbceb3302825262030d406024830152600482018390526003604483015260ea60020a621554930260648301529151919550600160a060020a0386169250632ef3accc916084808301926020929190829003018187876161da5a03f115610002575050604051513a62030d4002900395945050505050565b600080546040805160e060020a6338cc483102815290516100459392600160a060020a0316916338cc4831916004828101926020929190829003018187876161da5a03f1156100025750506040805180517fadf59f990000000000000000000000000000000000000000000000000000000082526004820194909452606060248201526003606482015260ea60020a6215549302608482015260a06044820152601260a48201527f687474703a2f2f6578616d706c652e636f6d000000000000000000000000000060c48201529051600160a060020a038416925063adf59f9991349160e4808301926020929190829003018185886185025a03f115610002575050505050565b61030c600061031e61011d565b60408051918252519081900360200190f35b60640290505b90565b670de0b6b3a764000004905061032456
Binary of the runtime part:
606060405260e060020a6000350463104d5fdd81146100475780631bf6c21b1461010c578063531b97d7146101195780638129fc1c146101f8578063b845c9a2146102ff575b005b61030c600080546040805160e060020a6338cc483102815290518392600160a060020a0316916338cc4831916004828101926020929190829003018187876161da5a03f11561000257505060408051805160e260020a630bbceb3302825262030d406024830152600482018390526003604483015260ea60020a621554930260648301529151919350600160a060020a0384169250632ef3accc916084828101926020929190829003018188876161da5a03f115610002575050604051519250505090565b61030c600061032761011d565b61030c5b6000600060006000600060009054906101000a9004600160a060020a0316600160a060020a03166338cc48316040518160e060020a0281526004018090506020604051808303816000876161da5a03f11561000257505060408051805160e260020a630bbceb3302825262030d406024830152600482018390526003604483015260ea60020a621554930260648301529151919550600160a060020a0386169250632ef3accc916084808301926020929190829003018187876161da5a03f115610002575050604051513a62030d4002900395945050505050565b600080546040805160e060020a6338cc483102815290516100459392600160a060020a0316916338cc4831916004828101926020929190829003018187876161da5a03f1156100025750506040805180517fadf59f990000000000000000000000000000000000000000000000000000000082526004820194909452606060248201526003606482015260ea60020a6215549302608482015260a06044820152601260a48201527f687474703a2f2f6578616d706c652e636f6d000000000000000000000000000060c48201529051600160a060020a038416925063adf59f9991349160e4808301926020929190829003018185886185025a03f115610002575050505050565b61030c600061031e61011d565b60408051918252519081900360200190f35b60640290505b90565b670de0b6b3a764000004905061032456