Skip to content

Commit

Permalink
Safe wallet support (#295)
Browse files Browse the repository at this point in the history
* Initial commit

* Initial commit

* multichain

* multi chain support

* test

* Test

* Update

* Add changeset

* Fix lockfile

---------

Co-authored-by: Agustin Armellini Fischer <[email protected]>
  • Loading branch information
Fbartoli and 0xaguspunk authored Feb 5, 2025
1 parent a21a1f3 commit 3d3dc2e
Show file tree
Hide file tree
Showing 14 changed files with 828 additions and 8 deletions.
6 changes: 6 additions & 0 deletions typescript/.changeset/honest-countries-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"goat-examples-langchain-safe": patch
"@goat-sdk/wallet-safe": patch
---

Release package
3 changes: 3 additions & 0 deletions typescript/examples/langchain/safe/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OPENAI_API_KEY=
WALLET_PRIVATE_KEY=
RPC_PROVIDER_URL=
15 changes: 15 additions & 0 deletions typescript/examples/langchain/safe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Langchain with viem Example

## Setup

Copy the `.env.template` and populate with your values.

```
cp .env.template .env
```

## Usage

```
npx ts-node index.ts
```
46 changes: 46 additions & 0 deletions typescript/examples/langchain/safe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { ChatPromptTemplate } from "@langchain/core/prompts";
import { Ollama } from "@langchain/ollama";
import { AgentExecutor, createStructuredChatAgent } from "langchain/agents";
import { pull } from "langchain/hub";

import { baseSepolia } from "viem/chains";

import { getOnChainTools } from "@goat-sdk/adapter-langchain";

import { sendETH } from "@goat-sdk/wallet-evm";
import { safe } from "@goat-sdk/wallet-safe";

require("dotenv").config();

const pk = process.env.WALLET_PRIVATE_KEY as `0x${string}`;

const llm = new Ollama({
model: "llama3.2:latest",
});

(async (): Promise<void> => {
const prompt = await pull<ChatPromptTemplate>("hwchase17/structured-chat-agent");

const tools = await getOnChainTools({
// The wallet will be deployed on chain and requires eth beforehand.
wallet: await safe(pk, baseSepolia),
plugins: [sendETH()],
});

const agent = await createStructuredChatAgent({
llm,
tools,
prompt,
});

const agentExecutor = new AgentExecutor({
agent,
tools,
});

const response = await agentExecutor.invoke({
input: "Send 0.00000 eth to 0x0000000000000000000000000000000000000000",
});

console.log(response);
})();
25 changes: 25 additions & 0 deletions typescript/examples/langchain/safe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "goat-examples-langchain-safe",
"version": "0.1.0",
"description": "",
"private": true,
"scripts": {
"test": "vitest run --passWithNoTests"
},
"author": "",
"license": "MIT",
"dependencies": {
"@goat-sdk/adapter-langchain": "workspace:*",
"@goat-sdk/core": "workspace:*",
"@goat-sdk/plugin-erc20": "workspace:*",
"@goat-sdk/wallet-evm": "workspace:*",
"@goat-sdk/wallet-safe": "workspace:*",
"@langchain/core": "catalog:",
"@langchain/ollama": "0.1.5",
"@langchain/openai": "^0.3.5",
"ai": "4.1.15",
"dotenv": "^16.4.5",
"langchain": "^0.3.2",
"viem": "2.21.49"
}
}
8 changes: 8 additions & 0 deletions typescript/examples/langchain/safe/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["index.ts"],
"exclude": ["node_modules", "dist"]
}
23 changes: 23 additions & 0 deletions typescript/packages/wallets/safe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Goat Wallet Viem 🐐 - TypeScript

## Installation
```
npm install @goat-sdk/wallet-safe
```

## Usage
```typescript
import { createWalletClient } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import { http } from "viem";

import { getOnChainTools } from "@goat-sdk/adapter-vercel-ai";
import { SafeWalletClient } from "./src";

const pk = process.env.WALLET_PRIVATE_KEY as `0x${string}`

const tools = await getOnChainTools({
wallet: new SafeWalletClient(pk, sepolia),
});
```
37 changes: 37 additions & 0 deletions typescript/packages/wallets/safe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@goat-sdk/wallet-safe",
"version": "0.1.0",
"sideEffects": false,
"files": ["dist/**/*", "README.md", "package.json"],
"scripts": {
"build": "tsup",
"clean": "rm -rf dist",
"test": "vitest run --passWithNoTests"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@goat-sdk/core": "workspace:*",
"@goat-sdk/wallet-evm": "workspace:*",
"@safe-global/protocol-kit": "5.2.1",
"@safe-global/safe-core-sdk-types": "5.1.0",
"permissionless": "0.2.28",
"viem": "catalog:"
},
"peerDependencies": {
"@goat-sdk/core": "workspace:*",
"@goat-sdk/wallet-evm": "workspace:*",
"viem": "catalog:"
},
"homepage": "https://ohmygoat.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/goat-sdk/goat.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/goat-sdk/goat/issues"
},
"keywords": ["ai", "agents", "web3"]
}
Loading

0 comments on commit 3d3dc2e

Please sign in to comment.