Deploy on AI EVM
This tutorial walks you through the process of deploying your first AI smart contract to Axonum Sepolia Testnet using the Remix in-browser Solidity IDE.
Last updated
This tutorial walks you through the process of deploying your first AI smart contract to Axonum Sepolia Testnet using the Remix in-browser Solidity IDE.
Last updated
Firefox or any Chromium-based browser (Chrome, Brave, Edge, etc.)
A browser-based wallet like MetaMask is convenient for development.
Get some testnet ETH from any of the faucets on Sepolia.
Go to the Axonum Bridge and connect your MetaMask wallet.
Deposit some testnet ETH to the bridge.
Wait for the deposit to be confirmed on the bridge.
Click this link to add Axonum Sepolia to your MetaMask wallet.
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.
After you approve the network, MetaMask will automatically try to switch to the Axonum Sepolia network. Click "Switch network" to continue.
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.
The most popular smart contract development language today is Solidity. In this tutorial, you'll be using a browser-based integrated development environment (IDE) called Remix.
Open the Remix IDE.
Feel free to step through the built-in tutorial before continuing.
When you are ready, create a new "blank" workspace.
Click "GitHub" to load the AI EVM Library.
Paste the following URL into the input box and click "Import": https://github.com/axonum/ai-evm-lib/AILib.sol
Create a new file in the workspace and name it AIContract.sol
.
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!
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.
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.
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.
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".
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".
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.
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.
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.
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.
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.)
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.)
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.
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.
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...".