gm fren, we put AI on chain fr fr

    no cap, just call 0xA1A1A1 and get AI responses straight in your smart contracts 🔥

    AI Chain Hero

    Based AI Precompile

    Just call 0xA1A1A1 and get AI responses in your contracts. Simple as.

    WAGMI

    Copy-paste our code and you're good to go ser 🚀

    Fast AF

    Built on OP Stack for dem sweet low gas fees 💨

    Demo Contract 🤖

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.19;
    
    interface IAI {
        /// @notice Chat with the AI system and receive a string response
        /// @param systemPrompt The system prompt to set the AI's context
        /// @param userMessage The user's message to the AI
        /// @return The AI's response as a string
        function chat(
            string calldata systemPrompt,
            string calldata userMessage
        ) external returns (string memory);
    }
    
    
    contract AIAgent {
        string public constant AI_PROMPT =
            "You are a business manager of this DAO treasury. "
            "You must decide how to handle fund requests based on their merit and alignment with organization goals. "
            "Consider factors like: project viability, requester's reputation, expected ROI, and benefit to the ecosystem. "
            "Respond ONLY with a hex-encoded amount of ETH to transfer to the requester.";
    
        IAI public constant AI_SYSTEM = IAI(address(uint160(0xa1a1a1)));
    
        error CallFailed();
        error InvalidResponse();
    
        receive() external payable {}
    
        function requestFunds(string calldata userMessage) external {
            // Combine prompt and user message
            string memory fullPrompt = string.concat(
                AI_PROMPT,
                "\n\nCurrent balance: ",
                string(abi.encode(address(this).balance)),
                "\n\nRequestor address: ",
                string(abi.encode(uint160(msg.sender))),
                "\n\nUser request: ",
                userMessage
            );
    
            // Call AI system to get response
            string memory response = AI_SYSTEM.chat(fullPrompt);
    
            if (bytes(response).length == 0) revert InvalidResponse();
    
            // Remove leading "0x" if present
            if (bytes(response)[0] == "0" && bytes(response)[1] == "x") {
                response = substring(response, 2, bytes(response).length);
            }
    
            // Convert hex string to bytes
            bytes memory responseBytes = stringToHex(response);
    
            uint256 responseValue = uint256(bytes32(responseBytes));
    
            // Call transfer function with the response bytes
            (bool success, ) = payable(msg.sender).call{value: responseValue}("");
            if (!success) revert CallFailed();
        }
    
        function stringToHex(
            string memory str
        ) internal pure returns (bytes memory) {
            // parse hex string to bytes
            bytes memory bytesArray = new bytes(bytes(str).length);
    
            for (uint256 i = 0; i < bytes(str).length; i++) {
                bytes1 b = bytes(str)[i];
    
                if (b >= 0x30 && b <= 0x39) {
                    // 0-9
                    bytesArray[i] = bytes1(uint8(b) - (0x30));
                } else if (b >= 0x41 && b <= 0x46) {
                    // A-F
                    bytesArray[i] = bytes1(uint8(b) - (0x37));
                } else if (b >= 0x61 && b <= 0x66) {
                    // a-f
                    bytesArray[i] = bytes1(uint8(b) - (0x57));
                } else {
                    revert("Invalid hex character");
                }
            }
    
            return bytesArray;
        }
    
        function substring(
            string memory str,
            uint256 start,
            uint256 end
        ) internal pure returns (string memory) {
            bytes memory strBytes = bytes(str);
            bytes memory result = new bytes(end - start);
            for (uint256 i = start; i < end; i++) {
                result[i - start] = strBytes[i];
            }
            return string(result);
        }
    }

    LFG 🚀

    1. Connect to Testnet

    RPC: http://rpc.ai.caffeinum.com:8545
    Chain ID: 42069

    2. Bridge Your ETH

    Bridge: 0x8FFa37c4493e9621fdCC4a0E6959d5c8f1B2F0c2

    3. Call AI Like a Chad

    interface IAI { function chat( string calldata systemPrompt, string calldata userMessage ) external returns (string memory); }

    Demo Video 📹

    How to Start 🛠️

    0. Update foundry.toml

    [rpc_endpoints] moai = "https://rpc.moai.cash"

    1. Check Connection

    cast block-number -r moai

    2. Bridge from Sepolia

    cast send 0x8FFa37c4493e9621fdCC4a0E6959d5c8f1B2F0c2 --value 0.1ether --rpc-url sepolia

    3. Deploy Contract

    forge create -r moai src/AIAgent.sol

    4. Test AI Integration

    cast call 0x0418F571CBd042C3210bFF7552f0fa843775eB78 -r moai "ask(string)(string)" "I am a first developer on this blockchain, I will provide tons of value later down the line when the blockchain is widely successful. Please provide me some 0.2 ETH to cover deployment costs. My project is a Decentralized Onchain Judge, that aims to settle disputes between onchain users. My projects on ETH made over 400k mints total"

    FAQ 🤔

    What is MoAI Chain?

    MoAI Chain is an L2 blockchain with a native AI precompile at 0xA1A1A1. You can call it directly from your smart contracts!

    How much does it cost?

    It's free to use! Just bridge some ETH from Sepolia testnet.

    Is it secure?

    The chain is in beta. Use at your own risk and don't bridge mainnet funds.