Comment on page
OO Quick Start
0 to 1 Optimistic Oracle integration by example.
The primary integration point into the UMA ecosystem is the Optimistic Oracle (OO). The OO is an oracle for arbitrary off-chain data which leverages an interactive escalation game between requesters, proposers and disputers and is secured by economic incentives.
If you prefer, you can also watch the following video tutorial in which we follow the step-by-step instructions described below.
You will be working through a simple smart contract that asks the oracle the question:
Q:Did the temperature on the 25th of July 2022 in Manhattan NY exceed 35c? A:1 for yes. 0 for no.After submitting the request, you will propose a solution using the UMA Optimistic Oracle UI.
Once through liveness, you will fetch the price from the smart contract. This shows the full lifecycle of an Optimistic Oracle data request on the Görli testnet, interacting with an actual Optimistic Oracle contract deployment, without needing to write any code or clone any repos. It should give you the basic intuition as to how the Optimistic Oracle works without too much overhead and is a great starting point before digging deeper. Let's get started!
To complete this tutorial you will need:
- 2.A wallet set up in Metamask.
First, we will work through the basic flow for asking the oracle for a piece of data. In this example, we are asking the Oracle for information on the weather but the request could be much more complex to could power any kind of smart contract system requiring data. See approved price identifies and the sample projects for more inspiration on what is possible with the OO.
The contract used in this tutorial is meant to be a simple data request flow. The contract exposes a simple
requestDatafunction which asks the OO a simple question about the weather.
- 2.Click on "gist-fba..." to see the files in the gist, and click
OO_GettingStarted.solto open to Solidity file.
- 3.In the far left hand menu, click the link to deploy and run transactions (which looks like the Ethereum logo and a right arrow).
- 4.In the "Environment" dropdown, choose "Injected Provider," and connect to your wallet. Make sure you are connected to Görli within your metamask wallet! You don't want to deploy to a real network and spend real gas, and the Görli Optimistic Oracle address hardcoded into the contract will not work on other networks.
- 5.Under the "Contract" dropdown, select
- 6.Click "Deploy" and confirm the transaction with your wallet.
- 7.You should now see the
OO_GettingStartedcontract under "Deployed Contracts". Clicking the dropdown carrot will reveal buttons for each of the functions in the contract.
requestDatato request the data specified in the contract's ancillary data, asking about the temperature in Manhattan on July 25th, 2022. Confirm the transaction in your wallet. This will submit a data request to the Optimistic Oracle.
What we've done in the above steps is: a) deploy a smart contract and b) submit a "price request" to the Optimistic oracle through the call to the Optimistic Oracle's
Now that we've asked the OO a question, it's time to propose a solution! The Optimistic Oracle works via an interactive escalation game wherein a) requesters ask questions b) proposers provide solutions and c) disputers monitor the proposals and dispute if they are invalid. If no dispute is done then the proposal is taken as valid. In this example, we'll be acting as the proposer who will be answering the question we asked in the previous section
- 2.Click "Connect Wallet" and make sure you are connected to the Görli testnet so that you can make a proposal. You should see all the information posed in the data request: the requester, identifier, timestamp, ancillary data and a link to the UMIP.
- 3.Submit your proposal (either
0). The actual value you submit is not super important in this case since this is just for testing purposes, but the correct response is
0. In doing this we are acting as the "proposer" providing a solution.
Once you've provided an answer to the question the proposal enters into a liveness period of 30 seconds. During this time it's up to Disputers to verify the correctness of what the proposer provided. Note that in a main net price request you'll normally set the liveness to much longer than 30 seconds (say two hours), the proposer will be bonded (if they propose wrong they lose money) and the proposer will be rewarded for providing a valid answer to the question.
Finally, we can fetch the data proposed in the previous step from the smart contract. For this example, we assume that there the proposed data was correct (was not disputed). Head back to your Remix tab and:
- 1.After the transaction finalizes, wait 30 seconds (the challenge window) and then click
OO_GettingStartedcontract on Remix. Confirm the transaction in your wallet. Because the proposal was not disputed within the challenge window, it can now be settled.
getSettledPriceto get the settled value. It should look like
getSettledPriceif you proposed an answer of
0. You can also see details in the console logs.
Congratulations! you've successfully integrated with the Optimistic Oracle, requested data, proposed data and fetched it within your smart contract! Note that the incentives in this toy example mean that there is no reason that anyone would provide the correct price (there was no reward for the proposers or disputes and there was no bond). A real world version of this should leverage custom bonds and more realistic liveness parameters.
Hopefully you got a basic understanding of the OO request flow from this getting started guide. Check out some of the example tutorials where we walk through more details on the functions discussed in this guide.