Docs

Discover how Phala's AI Agent Contract offers the essential tools to develop and profit from intelligent applications.

Explore Now

Brian Use Case: Intents Made Easy

Invalid Date

Overview

Intents is a buzzword that many Web3 natives may have heard about over the last year, and the concept has taken hold of many marketing campaigns. However, building intent-based solutions is not easy to do in a decentralized way. We are happy to announce our first integration to make intent-based dApps possible with the Brian AI Agent Contract Template. Now developers have access to an intent-based developer stack to get them building fast and towards the future.

Brian

Brian is your web3 AI assistant for making transactions, deploying contracts, and searching information and data by prompt in plain English. All the features available on the Brian App can be integrated into any protocol or wallet through the Brian APIs.

Brian’s mission is to set a new way of consuming web3 through text-based interaction and challenge the classic UX/UI of web3 that is often either too complex or too uninformative.

Brian Integration

Adding the Brian integration was easy and only took a few lines of code. Below is the “hello world” version of Brian’s AI Agent Contract. Here you can ask Brian a question as simple as “What is uniswap?” and Brian will respond with an answer. You can try it out now here.

const response = await fetch('https://api.brianknows.org/api/v0/agent/knowledge', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-Brian-Api-Key': `${brianApiKey}`
    },
    body: JSON.stringify({
        prompt: query,
    })
});

Building Intent-Based Swaps with Brian

From a recent hackathon a project named Jarvis built out this intent-based AI Agent utilizing Brian’s API. We can look at the details of the project and analyze how they leverage the API to build out their intent-based swaps.

Jarvis is a Collaborative Token-Gated Pragmatic Multi-Agent.

  • Collaborative: meant for teams (eg traders)
  • Token-Gated: only who own a Jarvis NFT with specific number can access it
  • Pragmatic: It can build transaction to be sent on chain
  • Multi-Agent: It combines many agents (potentially an infinite number of agents) to get the most powerful AI assistant ever.

Let’s start building the logic for how the transaction calldata can be generated from a prompt submitted by a user.

const response = await fetch('https://api.brianknows.org/api/v0/agent/transaction', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-Brian-Api-Key': `${brian_api_key}`
    },
    body: JSON.stringify({
        address: fromAddress,
        prompt: prompt,
    })
});

How Jarvis uses intents to compose transactions on Base is simple. User just enters in their prompt /tx swap 0.0001 ETH to LINK on base

User is then prompted to sign a transaction with the calldata returned from the Brian API query to execute the swap.

Conclusion

Brian’s API does not stop at generating intent-based swaps. With their additional features, users can build Web3 agents for education, Web3 Social bots, generative smart contracts, and much more! Adding the additional logic for a multi-agent system with AI Agent Contract makes the possibilities endless for developers.

For more detailed information and to start building:

About Phala

Phala Network is a decentralized cloud that offers secure and scalable computing for Web3.

With Phat Contracts, an innovative programming model enabling trustless off-chain computation, developers can create new Web3 use cases.

Get the latest Phala Content Straight To Your Inbox.