> ## Documentation Index
> Fetch the complete documentation index at: https://docs.delphai.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Integrate delphAI oracle into your prediction market in under 5 minutes

## Prerequisites

Before you begin, make sure you have:

<CardGroup cols={2}>
  <Card title="Smart Contract Knowledge" icon="code">
    Basic understanding of Solidity and smart contracts
  </Card>

  <Card title="Prediction Market Platform" icon="chart-line">
    A prediction market dApp that needs resolution
  </Card>
</CardGroup>

## Quick Integration

<Steps>
  <Step title="Connect to delphAI Contract">
    Import the delphAI interface and connect to the oracle.

    ```solidity theme={null}
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.20;

    interface IDelphAI {
        function createMarket(
            string memory question,
            string memory description,
            string[] memory possibleOutcomes,
            uint256 resolutionTimestamp
        ) external payable returns (uint256);

        function getMarket(uint256 marketId) external view returns (Market memory);
        function marketCreationFee() external view returns (uint256);
    }

    contract YourMarket {
        IDelphAI public immutable delphAI;

        constructor(address _delphAI) {
            delphAI = IDelphAI(_delphAI);
        }
    }
    ```
  </Step>

  <Step title="Create a Market">
    Create markets with AI resolution by paying the creation fee.

    ```solidity theme={null}
    function createYesNoMarket(
        string memory question,
        string memory description,
        uint256 resolutionTime
    ) external payable returns (uint256) {
        string[] memory outcomes = new string[](2);
        outcomes[0] = "Yes";
        outcomes[1] = "No";

        return delphAI.createMarket{value: msg.value}(
            question,
            description,
            outcomes,
            resolutionTime
        );
    }
    ```
  </Step>

  <Step title="Query Market Resolution">
    Check market status and get the AI resolution.

    ```solidity theme={null}
    function getWinningOutcome(uint256 marketId)
        external
        view
        returns (string memory)
    {
        Market memory market = delphAI.getMarket(marketId);
        require(market.status == MarketStatus.Resolved, "Not resolved yet");

        return market.possibleOutcomes[market.outcomeIndex];
    }

    function getAIResolution(uint256 marketId)
        external
        view
        returns (
            string memory explanation,
            string[] memory sources,
            uint8 confidence
        )
    {
        Market memory market = delphAI.getMarket(marketId);
        return (
            market.resolutionData,
            market.resolutionSources,
            market.resolutionConfidence
        );
    }
    ```
  </Step>

  <Step title="Test Your Integration">
    Test with a sample market on testnet.

    ```javascript theme={null}
    // Using ethers.js
    const creationFee = await delphAI.marketCreationFee();

    const tx = await yourMarket.createYesNoMarket(
        "Will BTC reach $100k by Dec 31, 2025?",
        "Resolves YES if Bitcoin >= $100,000 on any major exchange",
        1735689600, // Unix timestamp
        { value: creationFee }
    );

    await tx.wait();
    console.log('Market created and awaiting AI resolution!');
    ```
  </Step>
</Steps>

## Example: Full Market Integration

Here's a complete example of integrating delphAI into your prediction market:

```solidity theme={null}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IDelphAI {
    function createMarket(
        string memory question,
        string memory description,
        string[] memory possibleOutcomes,
        uint256 resolutionTimestamp
    ) external payable returns (uint256);

    function getMarket(uint256 marketId) external view returns (Market memory);
    function marketCreationFee() external view returns (uint256);
}

struct Market {
    uint256 id;
    address creator;
    string question;
    string description;
    string[] possibleOutcomes;
    uint256 createdAt;
    uint256 resolutionTimestamp;
    MarketStatus status;
    uint256 outcomeIndex;
    string resolutionData;
    string[] resolutionSources;
    uint8 resolutionConfidence;
    bytes proofData;
    uint256 resolvedAt;
    address resolvedBy;
}

enum MarketStatus { Open, Resolved, Cancelled }

contract PredictionMarket {
    IDelphAI public immutable delphAI;

    struct MarketData {
        uint256 delphAIMarketId;
        mapping(address => mapping(uint256 => uint256)) bets;
        uint256 totalPool;
    }

    mapping(uint256 => MarketData) public markets;

    constructor(address _delphAI) {
        delphAI = IDelphAI(_delphAI);
    }

    function createMarket(
        string memory question,
        string memory description,
        string[] memory outcomes,
        uint256 resolutionTime
    ) external payable returns (uint256) {
        // Get creation fee and create market on delphAI
        uint256 marketId = delphAI.createMarket{value: msg.value}(
            question,
            description,
            outcomes,
            resolutionTime
        );

        // Store market ID for later
        markets[marketId].delphAIMarketId = marketId;

        return marketId;
    }

    function placeBet(uint256 marketId, uint256 outcome)
        external
        payable
    {
        Market memory market = delphAI.getMarket(marketId);
        require(market.status == MarketStatus.Open, "Market not open");
        require(block.timestamp < market.resolutionTimestamp, "Market closed");

        markets[marketId].bets[msg.sender][outcome] += msg.value;
        markets[marketId].totalPool += msg.value;
    }

    function claimWinnings(uint256 marketId) external {
        Market memory market = delphAI.getMarket(marketId);
        require(market.status == MarketStatus.Resolved, "Not resolved");

        uint256 winningOutcome = market.outcomeIndex;
        uint256 userBet = markets[marketId].bets[msg.sender][winningOutcome];
        require(userBet > 0, "No winning bet");

        // Your payout logic here
        // Calculate and transfer winnings
        markets[marketId].bets[msg.sender][winningOutcome] = 0;
    }

    function getWinningOutcome(uint256 marketId)
        external
        view
        returns (string memory)
    {
        Market memory market = delphAI.getMarket(marketId);
        require(market.status == MarketStatus.Resolved, "Not resolved");

        return market.possibleOutcomes[market.outcomeIndex];
    }
}
```

## Integration Checklist

**Smart Contract Setup**

* Import delphAI interface
* Deploy your market contract
* Connect to delphAI oracle address
* Test on testnet

**Market Creation**

* Define clear, verifiable questions
* Set appropriate resolution times
* Specify possible outcomes
* Pay creation fee in BNB

**Query Resolution**

* Poll market status regularly
* Retrieve winning outcome when resolved
* Get AI explanation and reasoning
* Handle different market states (Open/Resolved/Cancelled)

**Testing & Security**

* Test full market lifecycle
* Audit your contract integration
* Handle edge cases
* Monitor gas costs

## Network Addresses

| Network     | Oracle Address                               | Chain ID |
| ----------- | -------------------------------------------- | -------- |
| BSC Mainnet | `0xA95E99848a318e37F128aB841b0CF693c1f0b4D1` | 56       |

## Next Steps

<CardGroup cols={2}>
  <Card title="Core Concepts" icon="book" href="/core-concepts/prediction-markets">
    Understand how delphAI resolves markets
  </Card>

  <Card title="Resolution Criteria" icon="brain" href="/ai-oracle/resolution-criteria">
    Learn how to write effective criteria
  </Card>

  <Card title="Smart Contract API" icon="code" href="/contracts/oracle-contract">
    Explore the full contract interface
  </Card>

  <Card title="Best Practices" icon="star" href="/guides/best-practices">
    Follow integration best practices
  </Card>
</CardGroup>

## Need Help?

<Card title="Developer Support" icon="discord" href="https://discord.gg/delphai">
  Join our Discord for developer support and integration help
</Card>
