> For the complete documentation index, see [llms.txt](https://whitepaper.gmr.center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.gmr.center/gmr-center/leet-lotto/chainlink-integration.md).

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