Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/polygon-mainnet-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"w3gpt": patch
---

Add typed Polygon mainnet and Amoy contract deployment support, package export
metadata, tests, and a prepack build so published releases include executable
artifacts.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ jobs:

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Build
run: bun run build

- name: Test
run: bun run test

- name: Verify package contents
working-directory: packages/w3gpt
run: npm pack --dry-run
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
version: bun ci:version
publish: bun ci:release
version: bun changeset version
publish: bun changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Useful commands:

The SDK mirrors the public Web3GPT skill flow:

1. Start a chat with no params
1. Call `deployContract` with an explicit Polygon mainnet (137) or Amoy
(80002) chain ID, or start a lower-level chat with no params
2. Save the returned `chatId`
3. Send follow-up messages with the same `chatId`
4. Add `history=true` or `full=true` when you want the full simplified history
Expand Down
25 changes: 16 additions & 9 deletions apps/docs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import styles from "./page.module.css";

const installSnippet = `npm install w3gpt`;

const quickstartSnippet = `import { w3gpt } from "w3gpt";
const quickstartSnippet = `import { PolygonChainId, w3gpt } from "w3gpt";

const client = w3gpt();

const started = await client.startChat();
const prepared = await client.deployContract({
chainId: PolygonChainId.Mainnet,
prompt: "An ERC20 named GrantProof with symbol GRANT and fixed supply.",
});

console.log(prepared.response);

const reply = await client.chat({
chatId: started.chatId,
message: "Deploy an ERC20 on Polygon mainnet with 1,000,000 supply",
const deployed = await client.chat({
chatId: prepared.chatId,
message: "Yes. I confirm deployment to Polygon mainnet, chain ID 137.",
});

console.log(reply.response);`;
console.log(deployed.response);`;

const historySnippet = `const history = await client.chat({
chatId: started.chatId,
chatId: deployed.chatId,
history: true,
});

Expand Down Expand Up @@ -62,7 +67,9 @@ export default function Home() {
<article className={styles.card}>
<h2>Model</h2>
<ul>
<li>Create a chat with no params</li>
<li>Select Polygon mainnet (137) or Amoy (80002)</li>
<li>Generate and review with one typed helper</li>
<li>Confirm deployment in the same chat</li>
<li>Reuse the returned chatId</li>
<li>Send messages through the same endpoint</li>
<li>Add history=true when you need full history</li>
Expand All @@ -73,7 +80,7 @@ export default function Home() {
<section className={styles.section}>
<div className={styles.sectionHeader}>
<p className={styles.kicker}>Quickstart</p>
<h2>Use the SDK as a thin wrapper over /api/skill.</h2>
<h2>Generate and deploy on Polygon mainnet.</h2>
</div>
<pre>{quickstartSnippet}</pre>
</section>
Expand Down
7 changes: 6 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lefthook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: pnpx @biomejs/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
run: bunx --bun @biomejs/biome@2.1.1 check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "turbo run dev",
"check": "biome check",
"check:fix": "biome check --write",
"test": "turbo run test",
"tsc": "turbo run tsc",
"clean": "turbo run clean"
},
Expand Down
101 changes: 78 additions & 23 deletions packages/w3gpt/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,74 @@
# w3gpt

TypeScript client for the Web3GPT skill endpoint.

The SDK is intentionally simple:

- call with no params to create a new chat
- keep the returned `chatId`
- pass that `chatId` on later calls to continue the same thread
- set `history=true` or `full=true` if you want the full simplified history back
TypeScript client for generating and deploying smart contracts through the
Web3GPT skill endpoint. Polygon mainnet and Polygon Amoy are explicit,
type-checked deployment targets.

## Installation

```bash
npm install w3gpt
# or
pnpm add w3gpt
# or
bun add w3gpt
# or
npm install w3gpt
```

## Usage
No API key or environment variable is required.

## Deploy on Polygon mainnet

```ts
import { w3gpt } from "w3gpt";
import { PolygonChainId, w3gpt } from "w3gpt";

const client = w3gpt();

const prepared = await client.deployContract({
chainId: PolygonChainId.Mainnet,
prompt: "An ERC20 named GrantProof with symbol GRANT and fixed supply of 1,000,000 tokens.",
});

// Review the generated contract and requested network before confirming.
console.log(prepared.response);

const deployed = await client.chat({
chatId: prepared.chatId,
message: "Yes. I confirm deployment to Polygon mainnet, chain ID 137.",
});

console.log(deployed.response);
```

`deployContract` requires an explicit chain ID. It reuses a contract already
generated in the supplied chat when present; otherwise it asks the agent to
generate one. It then requests deployment plus the contract address,
transaction hash, and Polygonscan URL. The agent requires explicit confirmation
before broadcasting; keep the returned `chatId` and continue with
`client.chat()` after reviewing the contract and network.

## Test first on Polygon Amoy

```ts
const deployment = await client.deployContract({
chainId: PolygonChainId.Amoy,
prompt: "A minimal immutable message contract.",
});
```

| Network | SDK constant | Chain ID | Explorer |
| --- | --- | ---: | --- |
| Polygon mainnet | `PolygonChainId.Mainnet` | 137 | `https://polygonscan.com` |
| Polygon Amoy | `PolygonChainId.Amoy` | 80002 | `https://amoy.polygonscan.com` |

## Chat API

The lower-level chat API remains available for contract generation, follow-up
instructions, and other Web3GPT agents.

```ts
const started = await client.startChat();
console.log(started.chatId);

const reply = await client.chat({
chatId: started.chatId,
message: "Deploy an ERC20 on Polygon mainnet with 1,000,000 supply",
message: "Generate an ERC721 contract for event tickets.",
});

console.log(reply.response);
Expand All @@ -53,26 +90,43 @@ console.log(result.history);
### `w3gpt(config?)`

```ts
const client = w3gpt({
type W3GPTConfig = {
baseUrl?: string; // defaults to https://w3gpt.ai
fetch?: typeof fetch; // optional custom fetch implementation
});
fetch?: typeof globalThis.fetch; // optional custom fetch implementation
};
```

### `client.startChat(agentId?)`

Create a new chat and receive a `chatId`.

### `client.deployContract(params)`

```ts
type W3GPTDeployContractRequest = {
chainId: 137 | 80002;
prompt: string;
agentId?: string;
chatId?: string;
history?: boolean;
full?: boolean;
};
```

Start a generate/review/deploy flow through the agent on an explicitly selected
Polygon network. Confirm deployment in the same chat after reviewing the
generated contract and network.

### `client.chat(params?)`

```ts
const result = await client.chat({
type W3GPTChatRequest = {
agentId?: string;
chatId?: string;
message?: string;
history?: boolean; // defaults to false
full?: boolean; // alias for history=true
});
};
```

Response:
Expand All @@ -94,5 +148,6 @@ type W3GPTChatResponse = {

- `chatId` is the secret for continuing the thread.
- If you call `client.chat()` with no params, a new chat is created.
- Deployments happen through the agent conversation itself.
- Polygon mainnet deployment is supported through the skill endpoint.
- A deployment may require a follow-up message depending on the prompt.
- Polygon deployments happen through the agent/skill endpoint, not a browser
wallet connector.
Loading
Loading