The backend AI Smart Contract built in typescript that is running on Phala Network and interacting with The Graph's API using Langchain for controlling the actions with Anthropic Claude
- Exposes a public API interface for the frontend to interact with and hosted on Phala Network
- API receives two values (key: string and chatQuery: string)
- key is generated by setting secrets for a published agent
- chatQuery is appended by the user everytime they make a request
- API receives two values (key: string and chatQuery: string)
- Uses The Graph to interact with Uniswap API
- Uses Claude in the background to create AI Agents
- Has two simplistic AI Agent that decides the course of action
- one to decide the most appropriate API to call to get the data
- one to decide the most appropriate visualization to display in the frontend
Phala Network provides DeCC (Decentralized Cloud Computing) which allows users to upload their typescript project to be hosted and run on blockchain nodes as opposed to centralized providers like DigitalOcean, AWS and GCP. The nature of decentralized AI and high privacy suits the needs of typical web3 users, and is more comfortable for typical web3 users as well.
The Graph provides an indexing and querying service for Dapps' smart contract which effectively allows anybody to query the data exposed by the smart contract easily and efficiently without having to manually sort through the gigabytes of infomration on the blockchain. This efficiency is one of the key factors that we chose the Graph.
In order to start using the Graph's subgraphs, you have to get access to their API key:
- Visit this website https://thegraph.com/studio/
- Connect your wallet
- Navigate into the Graph Studio, and also navigate into the API Keys tab
- CLick the "Create API Keys" button, and enter the necessary details.
- You can now access your API key.
- https://gateway.thegraph.com/api/your-api-key-here/subgraphs/id/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV The URL above is using
As the dApp is geared towards showing DeFi-related data, the Uniswap subgraph would be the best choice because it provides comprehensive data on liquidity pools, swaps, token prices, and transaction volumes within the Uniswap V3 protocol, allowing users to track key metrics for various assets.
The dApp uses fetch for fetching the subgraph data. The format is as the following: ''' const requestObject = await fetch( url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ query }), } ) const response = await requestObject.json(); '''
You can always get started by cloning the repo
git clone [email protected]:DefiDash/ai-agent-contract.git
Before proceeding, you might want to setup the environment variabls
THIRDWEB_API_KEY="XXXX"
{
"claudeApiKey":"XXXX"
}
npm run build # build the appplication
npm run test # test the application
npm run publish-agent # publish the agent
npm run set-secrets # set the secrets (use the API here from the frontend)