> ## 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.

# Oracle Contract

> Complete API reference for the DelphAI oracle smart contract

## Contract Overview

The DelphAI contract provides an AI-powered resolution oracle for prediction markets. Platforms can create markets on DelphAI by paying a creation fee, and the AI resolver will automatically resolve them at the scheduled time.

## Contract Addresses

| Network     | Contract Address                             |
| ----------- | -------------------------------------------- |
| BSC Mainnet | `0xA95E99848a318e37F128aB841b0CF693c1f0b4D1` |
| BSC Testnet | `0xA95E99848a318e37F128aB841b0CF693c1f0b4D1` |

## Market Functions

### createMarket

Create a new prediction market with AI resolution.

```solidity theme={null}
function createMarket(
    string memory question,
    string memory description,
    string[] memory possibleOutcomes,
    uint256 resolutionTimestamp
) external payable returns (uint256 marketId);
```

**Parameters**:

* `question` - The market question
* `description` - Additional context and resolution criteria
* `possibleOutcomes` - Array of possible outcome strings (minimum 2)
* `resolutionTimestamp` - Unix timestamp when AI should resolve the market

**Returns**:

* `marketId` - Unique identifier for the created market

**Requirements**:

* msg.value must be greater than or equal to marketCreationFee
* question must not be empty
* possibleOutcomes must have at least 2 options
* resolutionTimestamp must be in the future

**Example**:

```solidity theme={null}
uint256 fee = delphAI.marketCreationFee();

string[] memory outcomes = new string[](2);
outcomes[0] = "Yes";
outcomes[1] = "No";

uint256 marketId = delphAI.createMarket{value: fee}(
    "Will BTC reach 100k by December 31, 2025?",
    "Market resolves YES if Bitcoin is above 100k USD",
    outcomes,
    1735689599
);
```

**Emits**: `MarketCreated` event

***

### resolveMarket

Resolve a market with AI-generated outcome (only resolver).

```solidity theme={null}
function resolveMarket(
    uint256 marketId,
    uint256 outcomeIndex,
    string memory resolutionData,
    string[] memory resolutionSources,
    uint8 resolutionConfidence,
    bytes memory proofData
) external;
```

**Parameters**:

* `marketId` - The market to resolve
* `outcomeIndex` - Index of the winning outcome in possibleOutcomes array
* `resolutionData` - AI explanation and reasoning for the resolution
* `resolutionSources` - Array of source URLs used for resolution
* `resolutionConfidence` - Confidence level of the resolution (0-100)
* `proofData` - TEE attestation or cryptographic proof (future feature)

**Requirements**:

* Only callable by authorized resolver address
* Market must exist and be in Open status
* Current time must be greater than or equal to resolutionTimestamp
* outcomeIndex must be valid
* resolutionConfidence must be between 0 and 100

**Emits**: `MarketResolved` event

***

### cancelMarket

Cancel an open market (only creator or owner).

```solidity theme={null}
function cancelMarket(uint256 marketId) external;
```

**Parameters**:

* `marketId` - The market to cancel

**Requirements**:

* Caller must be market creator or contract owner
* Market must be in Open status

**Emits**: `MarketCancelled` event

***

## View Functions

### getMarket

Get complete market details.

```solidity theme={null}
function getMarket(uint256 marketId)
    external
    view
    returns (Market memory market);
```

**Returns**: Complete market data structure with all fields

***

### marketCreationFee

Get the current market creation fee.

```solidity theme={null}
function marketCreationFee() external view returns (uint256);
```

**Returns**: Fee amount in wei (BNB)

***

### resolver

Get the current authorized resolver address.

```solidity theme={null}
function resolver() external view returns (address);
```

***

### marketCounter

Get the total number of markets created.

```solidity theme={null}
function marketCounter() external view returns (uint256);
```

***

### getContractBalance

Get the contract BNB balance.

```solidity theme={null}
function getContractBalance() external view returns (uint256);
```

***

## Admin Functions

<Warning>
  These functions are restricted to the contract owner.
</Warning>

### setMarketCreationFee

Update the market creation fee.

```solidity theme={null}
function setMarketCreationFee(uint256 newFee) external;
```

**Emits**: `FeeUpdated` event

***

### setResolver

Update the authorized resolver address.

```solidity theme={null}
function setResolver(address newResolver) external;
```

**Emits**: `ResolverUpdated` event

***

### withdrawFees

Withdraw accumulated creation fees.

```solidity theme={null}
function withdrawFees(address payable to, uint256 amount) external;
```

**Emits**: `FeesWithdrawn` event

***

### recoverERC20

Recover ERC20 tokens sent to contract by mistake.

```solidity theme={null}
function recoverERC20(address token, address to, uint256 amount) external;
```

**Emits**: `TokensRecovered` event

***

## Market States

DelphAI markets have 3 possible states:

```solidity theme={null}
enum MarketStatus {
    Open,
    Resolved,
    Cancelled
}
```

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Events Reference" icon="bell" href="/contracts/events">
    Complete list of contract events
  </Card>

  <Card title="Integration Guide" icon="book" href="/quickstart">
    Step-by-step integration tutorial
  </Card>

  <Card title="Market Lifecycle" icon="circle-notch" href="/core-concepts/market-lifecycle">
    Understand the complete market lifecycle
  </Card>

  <Card title="Examples" icon="code" href="https://github.com/delphai-io/contracts/blob/main/INTEGRATION_EXAMPLE.sol">
    View integration examples on GitHub
  </Card>
</CardGroup>
