This example demonstrates how Lit Actions can be used to create tools and policies for on-chain agents. Tools allow agents to perform specific actions (i.e. "swap ETH for ARB") while policies dictate how a given tool is used (i.e. "If swap amount is greater than $100, require human approval").
The following Lit Action policies are immutable (deployed to IPFS), and require governance approval (via SAFE) in order to be executed by the agent.
Lit-AI-Agent.README.mp4
You'll need the following environment variables set up:
-
ETHEREUM_PRIVATE_KEY_1
- On Base mainnet:
- Safe deployment gas fees
- PKP Tools contract deployment
- Adding Lit Action IPFS CIDs to the PKP Tools contract
- First signature for Safe transactions
- On Lit's Chronicle Yellowstone:
- PKP minting costs
- Capacity Credits minting costs
- Requirements:
- A small amount of ETH on Base mainnet for gas fees
tstLPX
tokens on Chronicle Yellowstone blockchain (available from the faucet)
- On Base mainnet:
-
ETHEREUM_PRIVATE_KEY_2
- On Base mainnet:
- Second signature for Safe transactions
- Requirements:
- Small amount of ETH on Base mainnet for gas fees
- On Base mainnet:
-
OPENAI_API_KEY
- Required for the OpenAI GPT-4o-mini model execution
- Please ensure this model is enabled on your OpenAI API key
- Used for parsing intent and executing actions
- If you'd like to use a different model or provider, you can modify
./src/utils/subAgentUtils.ts
.
- Required for the OpenAI GPT-4o-mini model execution
-
BASESCAN_API_KEY
- Required for contract verification on BaseScan
BASE_RPC_URL
- RPC URL for Base mainnet (public URL provided in
.env.example
)
- RPC URL for Base mainnet (public URL provided in
- Clone the repository
- Navigate to the project directory:
cd lit-ai-agent
- Install dependencies:
yarn
- Create environment file:
cp .env.example .env
- Add required keys to
.env
- Compile the PKP Tools contract:
yarn compile
- Run the example:
yarn start
- Verify the contract (optional):
yarn verify
The first run will generate a safe-pkp-config.json
file containing Safe, PKP, and contract information, which is used for contract verification.
Implements a 2/2 multisig Safe for PKP action authentication.
- Two owners sign an authentication message
- Signatures are passed to Lit nodes' TEE (Trusted Execution Environment)
- Lit nodes verify signatures against Safe owners
- Session Signatures are generated, allowing the PKP to execute Lit Actions
- Handles token swaps via Uniswap V3
- Manages token approvals and execution
- Returns transaction hashes
- Executes basic ETH transfers
- Signs and processes transactions via PKP
- Returns transaction hash
- Unwraps WETH to ETH
- Returns transaction hash
- Gas optimization (2x current gas price)
- Error handling and status reporting
- Transaction verification
- Balance validation
./src/index.ts
: Main application logic
-
./src/utils/contractUtils.ts
: Contract interaction utilities- Tool permission management
- Contract queries
-
./src/utils/deployUtils.ts
: Deployment utilities- Contract deployment
- Safe transaction handling
- Balance checking
-
./src/utils/saveInfoUtils.ts
: Configuration management- Config saving/loading
- Deployment verification
-
./src/utils/subAgentUtils.ts
: Intent analysis and action matching
Pre-deployed actions with IPFS CIDs (source code available in src/litActions/
):
litActionAuth.ts
: Custom multisig authenticationlitActionSwap.ts
: Token swap functionalitylitActionSend.ts
: ETH transfer functionalitylitActionUnwrap.ts
: WETH unwrapping functionality
./contracts/PKPTools.sol
: PKP Tools contract implementation
./scripts/verify.cjs
: BaseScan contract verification script