-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add feature jsonrpc pugin * updates package * update-package.json * Fix PR --------- Co-authored-by: Agustin Armellini Fischer <[email protected]>
- Loading branch information
1 parent
e6ae292
commit 34596ce
Showing
11 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Goat JsonRpc Plugin 🐐 - TypeScript | ||
|
||
JsonRpc plugin for [Goat 🐐](https://ohmygoat.dev). Use this plugin to make Rpc calls to endpoints. | ||
|
||
## Installation | ||
``` | ||
npm install @goat-sdk/plugin-jsonrpc | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { jsonrpc } from "@goat-sdk/plugin-jsonrpc"; | ||
|
||
|
||
const plugin = jsonrpc({ | ||
endpoint: process.env.ENDPOINT_URL as string, | ||
}); | ||
``` | ||
|
||
## Available Actions | ||
|
||
### Call A Method | ||
- Make rpc call to an on chain method using an agent and a chat model e.g input | ||
-`make a JSONRpc call with this method {{ eth_blockNumber }}` | ||
|
||
|
||
## Goat | ||
|
||
<div align="center"> | ||
Go out and eat some grass. | ||
|
||
[Docs](https://ohmygoat.dev) | [Examples](https://github.com/goat-sdk/goat/tree/main/typescript/examples) | [Discord](https://discord.gg/2F8zTVnnFz)</div> | ||
|
||
## Goat 🐐 | ||
Goat 🐐 (Great Onchain Agent Toolkit) is an open-source library enabling AI agents to interact with blockchain protocols and smart contracts via their own wallets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@goat-sdk/plugin-jsonrpc", | ||
"version": "0.1.0", | ||
"files": ["dist/**/*", "README.md", "package.json"], | ||
"scripts": { | ||
"build": "tsup", | ||
"clean": "rm -rf dist", | ||
"test": "vitest run --passWithNoTests" | ||
}, | ||
"sideEffects": false, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
|
||
"dependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"zod": "catalog:" | ||
}, | ||
"peerDependencies": { | ||
"@goat-sdk/core": "workspace:*" | ||
}, | ||
"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"], | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./jsonrpc.plugin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Chain, PluginBase, WalletClientBase } from "@goat-sdk/core"; | ||
import { JSONRpcService } from "./jsonrpc.service"; | ||
|
||
export type JSONRpcOptions = { | ||
endpoint: string; | ||
}; | ||
|
||
export class JSONRpcPlugin extends PluginBase<WalletClientBase> { | ||
constructor({ endpoint }: JSONRpcOptions) { | ||
super("jsonrpc", [new JSONRpcService({ endpoint })]); | ||
} | ||
|
||
supportsChain = (chain: Chain) => true; | ||
} | ||
|
||
export function jsonrpc({ endpoint }: JSONRpcOptions) { | ||
return new JSONRpcPlugin({ endpoint }); | ||
} |
33 changes: 33 additions & 0 deletions
33
typescript/packages/plugins/jsonrpc/src/jsonrpc.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Tool, WalletClientBase } from "@goat-sdk/core"; | ||
import { JSONRpcBodySchema } from "./parameters"; | ||
|
||
export class JSONRpcService { | ||
private endpoint: string; | ||
|
||
constructor({ endpoint }: { endpoint?: string } = {}) { | ||
this.endpoint = endpoint ?? ""; | ||
} | ||
|
||
@Tool({ | ||
description: "Make a remote procedure call to a JSON RPC endpoint", | ||
}) | ||
async JSONRpcFunc(walletClient: WalletClientBase, parameters: JSONRpcBodySchema) { | ||
try { | ||
const url = new URL(`${this.endpoint}`); | ||
|
||
const response = await fetch(url.toString(), { | ||
method: "POST", | ||
body: JSON.stringify(parameters), | ||
headers: {}, | ||
}); | ||
console.log(response, "string"); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch: ${response.statusText}`); | ||
} | ||
|
||
return await response.json(); | ||
} catch (error) { | ||
throw Error(`Failed to call endpoint: ${error}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createToolParameters } from "@goat-sdk/core"; | ||
import { z } from "zod"; | ||
|
||
export class JSONRpcBodySchema extends createToolParameters( | ||
z.object({ | ||
method: z.string().describe("A string containing the name of the method to be invoked"), | ||
params: z | ||
.array(z.string()) | ||
.describe( | ||
"A structured value that holds the parameter value to be used during the invokation of the method", | ||
), | ||
id: z.number().describe("An identifier established by the client that must contain a string number or null"), | ||
jsonrpc: z | ||
.string() | ||
.describe("A string that specifies the version of the JSON-RPC protocol must be exactly {{'2.0'}}"), | ||
}), | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "../../../tsconfig.base.json", | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineConfig } from "tsup"; | ||
import { treeShakableConfig } from "../../../tsup.config.base"; | ||
|
||
export default defineConfig({ | ||
...treeShakableConfig, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"extends": ["//"], | ||
"tasks": { | ||
"build": { | ||
"inputs": ["src/**", "tsup.config.ts", "!./**/*.test.{ts,tsx}", "tsconfig.json"], | ||
"dependsOn": ["^build"], | ||
"outputs": ["dist/**"] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.