Skip to content
Closed
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
41 changes: 28 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@ on:
branches: [main]

jobs:
discover:
runs-on: ubuntu-latest
outputs:
examples: ${{ steps.find.outputs.examples }}
steps:
- uses: actions/checkout@v4

- name: Discover buildable examples
id: find
run: |
# Every example dir with a package.json that defines a `build` script
# (covers nested examples like eip7702/* and kms/*; skips node-only ones).
examples=$(
find examples -mindepth 2 -maxdepth 3 -name package.json -not -path '*/node_modules/*' |
while read -r pkg; do
if jq -e '.scripts.build' "$pkg" >/dev/null 2>&1; then
dirname "$pkg"
fi
done | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))'
)
echo "examples=$examples" >> "$GITHUB_OUTPUT"
echo "Discovered examples: $examples"

build:
needs: discover
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
example:
- nextjs-quickstart
- nextjs-send-transaction
- nextjs-sign-message
- nextjs-gas-sponsorship
- nextjs-ens-profiles
- nextjs-siwe
- nextjs-permissions
- nextjs-subscription
- vanilla-quickstart
- node-server-charge
example: ${{ fromJson(needs.discover.outputs.examples) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -31,11 +46,11 @@ jobs:
bun-version: latest

- name: Install dependencies
working-directory: examples/${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: bun install

- name: Build
working-directory: examples/${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: bun run build
env:
NEXT_PUBLIC_JAW_API_KEY: test_key
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ Official examples for the [JAW SDK](https://docs.jaw.id) — identity-first smar
| [kms/turnkey](./examples/kms/turnkey) | JAW smart accounts backed by [Turnkey](https://turnkey.com) server wallets |
| [kms/privy](./examples/kms/privy) | JAW smart accounts backed by [Privy](https://privy.io) server wallets |

### Minimal single-feature (Vite + React)

Tiny, focused demos — one integration and one post-connect action each. They also show the **embedded iframe** (default) vs **popup** transport explicitly.

| Example | Transport | Shows |
| --- | --- | --- |
| [wagmi-sign-message](./examples/wagmi-sign-message) | iframe | `personal_sign` via the wagmi connector |
| [wagmi-siwe-popup](./examples/wagmi-siwe-popup) | popup | Sign-In with Ethereum (EIP-4361) |
| [wagmi-gasless-sendcalls](./examples/wagmi-gasless-sendcalls) | iframe | gasless batched `wallet_sendCalls` (EIP-5792) with an ERC-20 paymaster |
| [wagmi-grant-permissions-popup](./examples/wagmi-grant-permissions-popup) | popup | grant a scoped permission (ERC-7715) |
| [wagmi-ens-identity](./examples/wagmi-ens-identity) | iframe | resolve the account's ENS subname |
| [core-popup-capabilities](./examples/core-popup-capabilities) | popup | `wallet_getCapabilities` (EIP-5792) via the raw provider, no wagmi |

## Quick Start

1. Get an API key at [dashboard.jaw.id](https://dashboard.jaw.id)
Expand All @@ -49,7 +62,7 @@ Official examples for the [JAW SDK](https://docs.jaw.id) — identity-first smar
npx nx dev nextjs-wagmi
```

Replace `nextjs-wagmi` with any example name: `nextjs-core`, `nextjs-headless-mode`, `node-quickstart`, `eip7702-node-quickstart`, `eip7702-turnkey`, `eip7702-privy-nextjs`, `kms-turnkey`, or `kms-privy`.
Replace `nextjs-wagmi` with any example name: `nextjs-core`, `nextjs-headless-mode`, `node-quickstart`, `eip7702-node-quickstart`, `eip7702-turnkey`, `eip7702-privy-nextjs`, `kms-turnkey`, `kms-privy`, `wagmi-sign-message`, `wagmi-siwe-popup`, `wagmi-gasless-sendcalls`, `wagmi-grant-permissions-popup`, `wagmi-ens-identity`, or `core-popup-capabilities`.

## Documentation

Expand Down
1,056 changes: 764 additions & 292 deletions bun.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/core-popup-capabilities/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_JAW_API_KEY=
27 changes: 27 additions & 0 deletions examples/core-popup-capabilities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Example: Core SDK, no wagmi (popup)

Integration **without wagmi** — uses the core SDK's EIP-1193 provider directly
(`JAW.create().provider.request(...)`), with the **popup** transport. Post-connect
action: read the smart account's **wallet capabilities** (EIP-5792
`wallet_getCapabilities`) — gasless/paymaster, atomic batching, permissions, per chain.

## Run

From the repo root, after `bun install`:

```bash
npx nx dev core-popup-capabilities
```

Set your API key in `examples/core-popup-capabilities/.env.local`:

```bash
VITE_JAW_API_KEY=<your-key>
# VITE_KEYS_URL=http://localhost:3001 # optional (local keys app)
```

## What it shows

- No wagmi / React Query — just `JAW.create()` and `provider.request(...)`.
- `eth_requestAccounts` connects (popup); `wallet_getCapabilities` reads what the account supports.
- The same provider also serves `personal_sign`, `wallet_sendCalls`, `wallet_grantPermissions`, etc.
12 changes: 12 additions & 0 deletions examples/core-popup-capabilities/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JAW Example — Core SDK (popup)</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions examples/core-popup-capabilities/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "core-popup-capabilities",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --port 5182",
"build": "vite build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@jaw.id/core": "^1.0.3",
"react": "19.2.6",
"react-dom": "19.2.6"
},
"devDependencies": {
"@types/react": "^19.2.0",
"@types/react-dom": "^19.2.0",
"@vitejs/plugin-react": "^6.0.0",
"typescript": "~5.9.2",
"vite": "^8.0.0"
}
}
84 changes: 84 additions & 0 deletions examples/core-popup-capabilities/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useState } from 'react';
import { JAW } from '@jaw.id/core';

/**
* Integration WITHOUT wagmi: the core SDK's EIP-1193 provider directly. Uses the
* POPUP transport. Post-connect action: read the smart account's wallet
* capabilities (EIP-5792 `wallet_getCapabilities`) — gasless/paymaster, atomic
* batching, permissions, etc., per chain.
*/
const sdk = JAW.create({
apiKey: import.meta.env.VITE_JAW_API_KEY ?? '',
appName: 'JAW Example — Core (popup)',
defaultChainId: 84532, // Base Sepolia
preference: {
...(import.meta.env.VITE_KEYS_URL ? { keysUrl: import.meta.env.VITE_KEYS_URL } : {}),
showTestnets: true,
transportMode: 'popup',
},
});

export function App() {
const [address, setAddress] = useState<string>();
const [capabilities, setCapabilities] = useState<unknown>();
const [error, setError] = useState<string>();

const connect = async () => {
setError(undefined);
try {
const accounts = (await sdk.provider.request({ method: 'eth_requestAccounts' })) as readonly `0x${string}`[];
setAddress(accounts[0]);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
}
};

const getCapabilities = async () => {
if (!address) return;
setError(undefined);
setCapabilities(undefined);
try {
const result = await sdk.provider.request({
method: 'wallet_getCapabilities',
params: [address as `0x${string}`],
});
setCapabilities(result);
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
}
};

return (
<main style={{ fontFamily: 'system-ui', maxWidth: 560, margin: '3rem auto', padding: '0 1rem' }}>
<h1>JAW — Core SDK (no wagmi)</h1>
<p style={{ color: '#666' }}>EIP-1193 provider directly · popup transport</p>

{!address ? (
<button onClick={connect}>Connect with JAW</button>
) : (
<>
<p>
Connected: <code>{address}</code>
</p>
<button onClick={getCapabilities}>Get wallet capabilities</button>
</>
)}

{capabilities !== undefined && (
<pre
style={{
marginTop: 16,
padding: 12,
background: '#f4f4f5',
borderRadius: 8,
whiteSpace: 'pre-wrap',
overflowWrap: 'anywhere',
}}
>
{JSON.stringify(capabilities, null, 2)}
</pre>
)}
{error && <p style={{ color: 'crimson' }}>⚠️ {error}</p>}
</main>
);
}
10 changes: 10 additions & 0 deletions examples/core-popup-capabilities/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

// No wagmi / react-query providers — this example talks to the EIP-1193 provider directly.
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>
);
15 changes: 15 additions & 0 deletions examples/core-popup-capabilities/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"types": ["vite/client"],
"verbatimModuleSyntax": true
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions examples/core-popup-capabilities/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
});
15 changes: 10 additions & 5 deletions examples/eip7702/node-quickstart/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ async function main() {

console.log('Step 1 — Create EIP-7702 account');

const signer = privateKeyToAccount(PRIVATE_KEY);
// Guaranteed defined by the env guard above; TS doesn't carry that narrowing
// of module-level consts into this nested function, so assert it here.
const signer = privateKeyToAccount(PRIVATE_KEY!);
const account = await Account.fromLocalAccount(
{
chainId: CHAIN_ID,
apiKey: JAW_API_KEY,
apiKey: JAW_API_KEY!,
...(PAYMASTER_URL ? { paymasterUrl: PAYMASTER_URL } : {}),
},
signer,
// The example's direct viem and @jaw.id/core's viem can resolve to two
// different versions in this workspace; the LocalAccount shape is identical
// but nominally distinct, so bridge it to the parameter type here.
signer as Parameters<typeof Account.fromLocalAccount>[1],
{ eip7702: true },
);

Expand Down Expand Up @@ -84,7 +89,7 @@ async function main() {
process.stdout.write(' waiting : ');

for (;;) {
const status = account.getCallStatus(id);
const status = await account.getCallStatus(id);
if (status && status.status !== 100) {
const label = status.status === 200 ? 'confirmed' : `failed (code ${status.status})`;
console.log(label);
Expand All @@ -110,7 +115,7 @@ async function main() {
process.stdout.write(' waiting : ');

for (;;) {
const status2 = account.getCallStatus(id2);
const status2 = await account.getCallStatus(id2);
if (status2 && status2.status !== 100) {
const label = status2.status === 200 ? 'confirmed' : `failed (code ${status2.status})`;
console.log(label);
Expand Down
1 change: 1 addition & 0 deletions examples/eip7702/node-quickstart/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022", "DOM"],
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
Expand Down
4 changes: 4 additions & 0 deletions examples/eip7702/privy-nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const metadata: Metadata = {
description: 'Upgrade a Privy embedded wallet to a JAW smart account via EIP-7702',
};

// The Privy provider initializes with a runtime app ID and can't be prerendered
// at build time, so render this route dynamically (at request time).
export const dynamic = 'force-dynamic';

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
Expand Down
13 changes: 12 additions & 1 deletion examples/eip7702/privy-nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
webpack: (config) => {
// @privy-io/react-auth references an optional Solana mini-app connector that
// this EVM-only example doesn't use and isn't installed. Stub it so the
// bundler doesn't fail to resolve it.
config.resolve.alias = {
...config.resolve.alias,
"@farcaster/mini-app-solana": false,
};
return config;
},
};

export default nextConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function SendTransaction() {
const { account } = useAccount();

// Single tx state
const [recipient, setRecipient] = useState(DUMMY_RECIPIENT);
const [recipient, setRecipient] = useState<string>(DUMMY_RECIPIENT);
const [amount, setAmount] = useState("0.0001");
const [txHash, setTxHash] = useState<string | null>(null);

Expand Down
4 changes: 3 additions & 1 deletion examples/nextjs-headless-mode/components/sign-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function SignMessage() {
messageObj[f.name] = f.value || (f.type === "address" ? account.address : "");
}

// Typed data is built dynamically from user input, so it can't satisfy
// viem's statically-typed TypedData generics; cast the runtime-built args.
const sig = await account.signTypedData({
domain: {
name: domainName,
Expand All @@ -69,7 +71,7 @@ export function SignMessage() {
types,
primaryType,
message: messageObj,
});
} as unknown as Parameters<typeof account.signTypedData>[0]);
setTypedSig(sig);
} catch (e) {
setError(e instanceof Error ? e.message : "Typed data signing failed");
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs-reown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@reown/appkit": "^1.7.8",
"@reown/appkit-adapter-wagmi": "^1.8.19",
"@tanstack/react-query": "^5.95.0",
"@wagmi/core": "^2.22.1",
"next": "16.2.1",
"react": "19.2.4",
"react-dom": "19.2.4",
Expand Down
Loading
Loading