OnChainAI purpose is to propose a fully decentralized way to interact onchain, between smartcontracts and AI
A running demo of OnChainAI is available on IPFS : https://onchain-ai.on-fleek.app/
Here is main screenshot;
Install via these commands:
git clone https://github.com/Kredeum/onchain-ai.git
cd onchain-ai
pnpm installSet these values in your ENV variables :
export PUBLIC_ALCHEMY_API_KEY=<YOUR_ALCHEMY_KEY>
export PUBLIC_WALLET_CONNECT_PROJECT_ID=<YOUR_WALLET_CONNECT_PROJECT_ID>Run the Dapp on local network with this command:
turbo startOr optionnaly, you can also run these commands in 3 different terminals, like in Scaffold-eth standard mode:
turbo chainturbo deployturbo startNote that OnChainAI will not fully work on anvil network (no ChainLink there...), so rather use a tesnet like base-sepolia or optimism-sepolia for your tests (avoid sepolia that is slower).
If you want to redeploy smartcontract (as an dev), you will also need to set these values:
ETHERSCAN_API_KEY=<YOUR_ETHERSCAN_API_KEY>: etherscan api keyVERIFIER_URL=https://api.etherscan.io/api: url associated with etherscan api key "OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>: openai api key
OPENAI_API_KEY will be uploaded in a secure way to ChainLink DON (don't use centralized S3 solutions also proposed by ChainLink)
Recommanded way is to use direnv command.
After direnv setup you only have to move example.env with your own values to .envrcfile
Other possible ways inludes :
- simplest way, run
source your.env - classic way, use
dotenv - chainLink secure way, use
env-encpackages
-
OnChainAI extensionis a Scaffold-eth-alt extension, allowing you to develop Dapps usingOpenAI GPT -
OnChainAIprotocol is an onchain solution for any smartcontracts to make AI calls. -
OnChainAIusesOpenAI GPT4o-miniwithChainLink Functions. EachOpenAIrequest launched byOnChainAIis sent by multipleChainLinkservers that have to reach consensus to return a unique answer.ChainLinkanswer can be retrieved only after a few blocks, and may take more than one minute, depending on the network. -
OnChainAIis not free (on mainnet) asChainLinkrequires someLINKtokens andOpenAIrequires some$. Default model will be a fixed price of0.0002 ethper request. BUT this will be changed in the future to a more dynamic pricing model. -
You can use
OnChainAIprotocol as is, with the contracts already deployed, or you can deploy your own, where you will be able to set your own configuration, and decide on the price of AI requests. -
OnChainAI extensionis available with aHardhatsetup with 3 specific AI tasks to help you start with theOnChainAIprotocol.
You can send your prompt to OnChainAI in different ways:
- using
Scaffold-eth debugpage ofOnChainAIdapp (out of the box) - using
OnChainAI UIincluded in this extension, via theAsk?menu link inOnChainAIdapp - via your smartcontracts using
OnChainAIprotocol
1 script is available for the OnChainAI admin : secrets
Admin task, to be used to upload your secrets to ChainLink
Ex: yarn hardhat --network baseSepolia ai secrets --expiration 10
Usage: hardhat [GLOBAL OPTIONS] ai secrets [--expiration <INT>]
OPTIONS:
--expiration Expiration time in minutes of uploaded secrets (default: 60)
secrets: Upload OnChainAI secrets to ChainLinkConfig file can be found at chainLink/config.json
A specific system prompt is used for each OpenAI request, you can view it inside the javascript code run by ChainLink DON : chainLink/source/onChainAI.js
-
ChainLink Functionsis currently inbeta. -
OpenAIprompt must be kept simple, asChainLink Functionshas a limited memory capacity -
OpenAIanswer must very short, in order forChainLink Functionsto be able to reach a consensus on an answer. i.e. you can ask '13 time 5 equal ?' but not ask 'Tell me a story'. And you can add to your prompt some requirements as: answer withone word,YES or NOortrue or false...
- implement other AI models :
Mistral,Claude,Lama3and otherOpenAImodels - deploy
OnChainAIon all networks supported byChainLink Functions(curently as of August 2024 : Ethereum, Arbitrum, Base, Optimism, Polygon, Avalanche) - deploy with same address on all networks
- propose a choice between multiple system prompts
