# Deploy on AI EVM

## Prerequisites

* Firefox or any Chromium-based browser (Chrome, Brave, Edge, etc.)
* A browser-based wallet like [MetaMask](https://support.metamask.io/getting-started/getting-started-with-metamask/) is convenient for development.
* Get some testnet ETH from any of the [faucets on Sepolia](https://faucetlink.to/sepolia).

## Bridge Testnet ETH to Axonum Sepolia

1. Go to the [Axonum Bridge](https://app.axonum.io/bridge/deposit) and connect your MetaMask wallet.

   <figure><img src="/files/lKJXO80NB6RZAHIAZU1F" alt=""><figcaption><p>Connect wallet</p></figcaption></figure>
2. Deposit some testnet ETH to the bridge.

   <figure><img src="/files/Ff30z4VoY7SBKhh27myJ" alt=""><figcaption><p>Deposit Sepolia ETH</p></figcaption></figure>
3. Wait for the deposit to be confirmed on the bridge.

   <figure><img src="/files/dKEFxqwT81Cch9VLwfvM" alt=""><figcaption><p>Deposit confirmed</p></figcaption></figure>

## Add Axonum Sepolia to MetaMask

1. Click [this link](https://add.axonum.io/?network=testnet) to add Axonum Sepolia to your MetaMask wallet.

   <figure><img src="/files/ZPwaxxo3vmwgev2pt0Gu" alt=""><figcaption></figcaption></figure>
2. You'll be presented with a popup from MetaMask asking if you'd like to add the network. Click "Approve" to add Axonum Sepolia to MetaMask.

   <figure><img src="/files/rSSDBWue4xQEywwBiHiZ" alt=""><figcaption><p>Add network to MetaMask</p></figcaption></figure>
3. After you approve the network, MetaMask will automatically try to switch to the Axonum Sepolia network. Click "Switch network" to continue.

   <figure><img src="/files/4Y3ynhy62UaGnDSQUaQg" alt=""><figcaption><p>Switch network</p></figcaption></figure>

## Check Your Wallet Balance

After you get some ETH on Axonum Sepolia, you can check your wallet balance in MetaMask. Make sure that your balance has updated before continuing. If you don't see any ETH in your wallet, double check that your MetaMask is connected to the Axonum Sepolia network.

## Write Your First AI Contract

The most popular smart contract development language today is [Solidity](https://docs.soliditylang.org/en/latest/). In this tutorial, you'll be using a browser-based integrated development environment (IDE) called Remix.

1. Open the [Remix IDE](https://remix.ethereum.org/).
2. Feel free to step through the built-in tutorial before continuing.
3. When you are ready, create a new "blank" workspace.

   <figure><img src="/files/KcFSnUwsEax03eqXBTgE" alt=""><figcaption><p>Create a new workspace</p></figcaption></figure>

   <figure><img src="/files/itJxyuaLz0L5PMU9JiL9" alt=""><figcaption><p>Choose "Blank" and click "OK"</p></figcaption></figure>
4. Click "GitHub" to load the AI EVM Library.

   <figure><img src="/files/XyTRWKSMW0XAKUc9UZPC" alt=""><figcaption><p>Load from GitHub</p></figcaption></figure>
5. Paste the following URL into the input box and click "Import": `https://github.com/axonum/ai-evm-lib/AILib.sol`

   <figure><img src="/files/4GzI5fGCeTYfmKMzusJA" alt=""><figcaption><p>Import AI EVM Library</p></figcaption></figure>
6. Create a new file in the workspace and name it `AIContract.sol`.

   <figure><img src="/files/zmwMbuSGIRfA5sPlWg5w" alt=""><figcaption><p>Create `AIContract.sol`</p></figcaption></figure>
7. Copy and paste the following code into the file you just created. Remix will detect copy/pasted code and give you a warning about it. This is meant to prevent you from accidentally running malicious code. Always be careful when copy/pasting code from the internet!

   ```solidity
   // SPDX-License-Identifier: MIT
   pragma solidity >=0.4.16 <=0.8.23;

   import "./github/axonum/ai-evm-lib/AILib.sol";

   contract AIContract {
       event Inference(bytes32 model_address, bytes input_data, uint256 output_size, bytes output);
       
       function inference(bytes32 model_address, bytes memory input_data, uint256 output_size) public {
           bytes memory output = AILib.inference(model_address, input_data, output_size);
           emit Inference(model_address, input_data, output_size, output);
       }
   }
   ```

The `AILib` contract is a library that makes it easy to call the AI precompile. The `AIContract` contract is a simple contract that calls the `inference` function in the `AILib` contract and emits an event with the results.

## Compile and Deploy Your AI Contract

1. By default, Remix will automatically compile your contract when you save it. You can also manually compile your contract by clicking the "Solidity Compiler" icon in the left sidebar and then clicking the "Compile" button. It's usually easier to leave automatic compilation enabled. You shouldn't see any compilation errors for this contract.

   <figure><img src="/files/1kL0ZznLYIPTyU57ZJxd" alt=""><figcaption><p>Compile contract</p></figcaption></figure>
2. Click on the "Deploy & run transactions" icon in the left sidebar to open the Deploy tab (it looks like an Ethereum logo with an arrow pointing to the right). You'll see some deployment options and a list of contracts that are currently compiled. Make sure `AIContract` is selected in the dropdown.

   <figure><img src="/files/jM0bwhH4rza5ORRyhF6A" alt=""><figcaption><p>Deploy tab</p></figcaption></figure>
3. By default, Remix will try to deploy your contract to a local, in-memory blockchain. This is useful for testing, but you'll need to change your environment to deploy to Axonum Sepolia for this tutorial. Click on the dropdown underneath the "Environment" heading and select "Injected Provider - MetaMask".
4. Once you've selected the "Injected Provider - MetaMask" option, MetaMask will show you a popup asking if you'd like to connect to Remix. Accept this request by clicking the "Connect" button. Make sure under the "Environment" dropdown, it says "Custom (1635282798) network".

   <figure><img src="/files/yj8SXukagLbbnGA22ZHF" alt=""><figcaption><p>Deploy to Axonum Sepolia</p></figcaption></figure>
5. You're now ready to deploy your contract! Click the orange "Deploy" button to deploy your contract to Axonum Sepolia. You'll be presented with another MetaMask popup asking you to confirm the transaction. Click the "Confirm" button to continue.
6. Axonum Sepolia is relatively fast, so transactions should confirm within just a few seconds. Remix will automatically detect when your transaction has confirmed and will show you your newly deployed contract under the "Deployed Contracts" heading within the Deploy tab.

## Interact With Your Contract

Now that you've deployed your contract, you can interact with it. Remix makes it easy to interact with your contract by providing a built-in user interface. You can use this interface to call functions on your contract and read its state.

1. Click on the arrow next to the name of your contract under the "Deployed Contracts" heading to expand it. You should see a list of functions that you can call on your contract.

   <figure><img src="/files/LSlFtJNHcqw8OmVLSUPp" alt=""><figcaption><p>Deployed contract</p></figcaption></figure>
2. Now you'll call an inference in Axonum's AI EVM. Expand the `inference` function by clicking on the arrow next to the input box. Fill in the input boxes with the following values:

   * `model_address`: `0x0000000000000000000000000000000000000000000000000000000000000001` (This is the address of the model you want to use. You can find more models [here](/chain/precompiles.md#available-models).)
   * `input_data`: `0x457468657265756d` (This is the hex representation of the string "Ethereum". You can change this to any input data you like.)
   * `output_size`: `200` (This is the size of the output data in bytes. You can change this to any size you like, but preferably not too large.)

   <figure><img src="/files/xeGDpVbiSKCAAifrqhr5" alt=""><figcaption><p>Inference parameters</p></figcaption></figure>
3. Click the orange "transact" button to call the `inference` function on your contract. You'll be presented with another MetaMask popup asking you to confirm the transaction. Click the "Confirm" button to continue.
4. Your transaction should confirm within a few seconds. Once it confirms, you'll see the results of the inference in the console log. You should see an event with the input data you provided and the output data from the inference.

   <figure><img src="/files/ipxZywQWOFB3UVNycqg3" alt=""><figcaption><p>Inference event</p></figcaption></figure>

   The output data in this case is `0x457468657265756d20697320616e206f70656e2d736f757263652c20626c6f636b636861696e2d626173656420706c6174666f726d207468617420656e61626c657320646576656c6f7065727320746f206275696c6420616e64206465706c6f7920646563656e7472616c697a6564206170706c69636174696f6e732028644170707329207573696e6720736d61727420636f6e7472616374732e204974207761732070726f706f73656420696e206c617465203230313320627920566974616c696b2042757465...` which is the hex representation of the string "Ethereum is an open-source, blockchain-based platform that enables developers to build and deploy decentralized applications (dApps) using smart contracts. It was proposed in late 2013 by Vitalik Bute...".


---

# 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://docs.axonum.io/builders/deploy-on-ai-evm.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.
