# Chainlink Integration

[Visit Chainlink](https://chain.link)

Leet Lotto relies on Chainlink services for tamper-proof randomness and autonomous upkeep.

### Verifiable Randomness

```solidity
// ⚠️ Simplified example
function drawWinner(uint256 lottoId) external onlyUpkeep {
    bytes32 requestId = VRFCoordinator.requestRandomWords(
        keyHash,
        subscriptionId,
        3,          // confirmations
        200000,     // gasLimit
        1           // words
    );
    vrfRequests[requestId] = lottoId;
}
```

* **Chainlink VRF** returns a random value used to pick the winning ticket index.
* Anyone can verify the randomness on-chain.

### Automation / Upkeep

```solidity
// ⚠️ Simplified example
function checkUpkeep(bytes calldata) external view returns (bool, bytes memory) {
    bool isReady = block.timestamp >= closingTime && !winnerSelected;
    return (isReady, bytes(""));
}

function performUpkeep(bytes calldata) external {
    require(block.timestamp >= closingTime, "Lottery still open");
    _startVRFRequest();
}
```

* Draws trigger automatically when a lotto’s closing time hits.
* Removes human intervention and schedule risk.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.gmr.center/gmr-center/leet-lotto/chainlink-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
