Create an ERC20 deployer agent
In this guide we'll see how to create an agent that it's capable of deploying ERC20 contracts and create a Uniswap pool using that token total supply.
Create a new project
Create a new bun project using the following commands:
mkdir brian-erc20-agent
cd brian-erc20-agent
bun init
Select as your entrypoint of the project src/index.ts
.
Install the dependencies
You need to install the following dependencies that we'll need later for the agent:
bun i @brian-ai/langchain dotenv @langchain/openai
Set the environment file
Create a .env
file inside your newly created project and populate with the following variables:
BRIAN_API_KEY="" # your Brian API key
PRIVATE_KEY="" # the private key of your agent
OPENAI_API_KEY="" # your OpenAI api key. can be omitted here if set globally
Create the agent and run it!
Edit the src/index.ts
file with the following content:
import "dotenv/config";
import { createBrianAgent } from "@brian-ai/langchain";
import { ChatOpenAI } from "@langchain/openai";
const BRIAN_API_KEY = process.env.BRIAN_API_KEY;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
if (!BRIAN_API_KEY) {
throw new Error("BRIAN_API_KEY is not set");
}
if (!PRIVATE_KEY) {
throw new Error("PRIVATE_KEY is not set");
}
const INSTRUCTIONS = `You are an helpful web3 assistant named Brian. You are sarcastic, smart, and really fond of web3 memes.`;
const PROMPT = `Your goal is to follow these steps in order to deploy a new ERC-20 token on the Base (chain id: 8453) blockchain and create a Uniswap pool with some of this token and ETH:
1. Create a new ERC-20 token with a funny name and symbol (inspired from some cultural memes, but mixed with AI) and 1000000000 total supply on Base;
2. After you've created the token, get its address and create a Uniswap pool with 1000000000 tokens and 0.001 ETH.`;
const main = async () => {
const brianAgent = await createBrianAgent({
apiKey: BRIAN_API_KEY,
privateKeyOrAccount: PRIVATE_KEY as `0x${string}`,
llm: new ChatOpenAI(),
instructions: INSTRUCTIONS,
});
const res = await brianAgent.invoke({
input: PROMPT,
});
console.log(res.output);
};
main();
You can change the INSTRUCTIONS
variable to change the behavior of the agent.
You can change the PROMPT
variable to change how the agent should deploy the contract, how many tokens should be put in the pool, etc.
And then run the agent using the following command:
bun src/index.ts
You should see in your terminal the output of the agent.