|
| 1 | +!!! info "Content disclaimer" |
| 2 | + |
| 3 | + Please view the third-party content disclaimer [here](https://github.com/0xPolygon/polygon-docs/blob/main/CONTENT_DISCLAIMER.md). |
| 4 | + |
| 5 | +[ORA](https://ora.io) is Ethereum's Trustless AI. ORA is the verifiable oracle protocol that brings AI and complex compute onchain. |
| 6 | +ORA’s main product, **Onchain AI Oracle (OAO)**, brings AI onchain. |
| 7 | + |
| 8 | +ORA breaks down the limitations of smart contracts by offering verifiable AI inference, so developers can innovate freely. |
| 9 | + |
| 10 | +## OAO Quickstart |
| 11 | + |
| 12 | +This quickstart is designed to help you to build a smart-contract on Polygon able to interact with OAO. You can find more details in [our docs quickstart.](https://docs.ora.io/doc/oao-onchain-ai-oracle/develop-guide) |
| 13 | + |
| 14 | +### Workflow |
| 15 | + |
| 16 | +1. The user contract sends the AI request to OAO on Polygon, by calling `requestCallback` function on the OAO contract. |
| 17 | +2. Each AI request will initiate an opML inference. |
| 18 | +3. OAO will emit a `requestCallback` event which will be collected by opML node. |
| 19 | +4. opML node will run the AI inference, and then upload the result on Polygon, waiting for the challenge period. |
| 20 | + 1. During the challenge period, the opML validators will check the result, and challenge it if the submitted result is incorrect. |
| 21 | + 2. If the submitted result is successfully challenged by one of the validators, the submitted result will be updated on Polygon. |
| 22 | + 3. After the challenge period, the submitted result on chain is finalized. |
| 23 | +5. When the result is uploaded or updated on Polygon, the provided AI inference in opML will be dispatched to the user's smart contract via its specific callback function. |
| 24 | + |
| 25 | +## Integration |
| 26 | + |
| 27 | +### Overview |
| 28 | + |
| 29 | +To integrate with OAO, you will need to write your own contract. |
| 30 | + |
| 31 | +To build with AI models of OAO, we provided an example of contract using OAO: [Prompt](https://polygonscan.com/address/0xC20DeDbE8642b77EfDb4372915947c87b7a526bD). |
| 32 | + |
| 33 | +### Smart Contract Integration |
| 34 | + |
| 35 | +1. Inherit `AIOracleCallbackReceiver` in your contract and bind with a specific OAO address: |
| 36 | + |
| 37 | +```solidity |
| 38 | +constructor(IAIOracle _aiOracle) AIOracleCallbackReceiver(_aiOracle) {} |
| 39 | +``` |
| 40 | + |
| 41 | +2. Write your callback function to handle the AI result from OAO. Note that only OAO can call this function: |
| 42 | + |
| 43 | +```solidity |
| 44 | +function aiOracleCallback(uint256 requestId, bytes calldata output, bytes calldata callbackData) external override onlyAIOracleCallback() |
| 45 | +``` |
| 46 | + |
| 47 | +3. When you want to initiate an AI inference request, call OAO as follows: |
| 48 | + |
| 49 | +```solidity |
| 50 | +aiOracle.requestCallback(modelId, input, address(this), gas_limit, callbackData); |
| 51 | +``` |
| 52 | + |
| 53 | +## Reference |
| 54 | + |
| 55 | +2 models are available on Polygon: Stable Diffusion (ID: 50), Llama3 8B Instruct (ID: 11). |
| 56 | + |
| 57 | +[Prompt](https://docs.ora.io/doc/oao-onchain-ai-oracle/reference) and [SimplePrompt](https://docs.ora.io/doc/oao-onchain-ai-oracle/reference) are both example smart contracts interacted with OAO. |
| 58 | + |
| 59 | +For simpler application scenarios (eg. Prompt Engineering based AI like GPTs), you can directly use Prompt or SimplePrompt. |
| 60 | + |
| 61 | +SimplePrompt saves gas by only emitting the event without storing historical data. |
| 62 | + |
| 63 | +Polygon PoS Mainnet: |
| 64 | + |
| 65 | +- OAO Proxy: [0x0A0f4321214BB6C7811dD8a71cF587bdaF03f0A0](https://polygonscan.com/address/0x0A0f4321214BB6C7811dD8a71cF587bdaF03f0A0) |
| 66 | +- Prompt: [0xC20DeDbE8642b77EfDb4372915947c87b7a526bD](https://polygonscan.com/address/0xC20DeDbE8642b77EfDb4372915947c87b7a526bD) |
| 67 | +- SimplePrompt: [0xC3287BDEF03b925A7C7f54791EDADCD88e632CcD](https://polygonscan.com/address/0xC3287BDEF03b925A7C7f54791EDADCD88e632CcD) |
| 68 | + |
| 69 | +## Useful links: |
| 70 | + |
| 71 | +- Read [ORA documentation](https://docs.ora.io) |
| 72 | +- [Join our Discord](https://discord.gg/ora-io) where our team can help you |
| 73 | +- Follow us [on X](https://x.com/OraProtocol) |
0 commit comments