diff --git a/examples/logs_pending_transactions/index.html b/examples/logs_pending_transactions/index.html new file mode 100644 index 0000000000..3518f18091 --- /dev/null +++ b/examples/logs_pending_transactions/index.html @@ -0,0 +1,12 @@ + + + + + + + +

Pending Transactions Example

+
Loading...
+ + + diff --git a/examples/logs_pending_transactions/index.ts b/examples/logs_pending_transactions/index.ts new file mode 100644 index 0000000000..cc33dc0e86 --- /dev/null +++ b/examples/logs_pending_transactions/index.ts @@ -0,0 +1,24 @@ +import { http, createPublicClient } from "viem"; +import { sepolia } from "viem/chains"; + +const client = createPublicClient({ + chain: sepolia, + transport: http(), +}); + +const el = document.getElementById("app"); + +// Polling frequency (in ms) +const pollingInterval = 1000; + +client.watchPendingTransactions({ + poll: true, + pollingInterval, + onTransactions: (hashes) => { + for (let i = 0; i < hashes.length; i++) { + let newElement = document.createElement("p"); + newElement.textContent = hashes[i]; + el!.appendChild(newElement); + } + }, +}); diff --git a/examples/logs_pending_transactions/package.json b/examples/logs_pending_transactions/package.json new file mode 100644 index 0000000000..a50b1d6443 --- /dev/null +++ b/examples/logs_pending_transactions/package.json @@ -0,0 +1,15 @@ +{ + "name": "example-event-logs", + "private": true, + "type": "module", + "scripts": { + "dev": "vite" + }, + "dependencies": { + "viem": "latest" + }, + "devDependencies": { + "typescript": "^5.0.3", + "vite": "^4.4.2" + } +} \ No newline at end of file diff --git a/examples/logs_pending_transactions/tsconfig.json b/examples/logs_pending_transactions/tsconfig.json new file mode 100644 index 0000000000..4d4b0364bd --- /dev/null +++ b/examples/logs_pending_transactions/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ESNext", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ESNext", "DOM"], + "moduleResolution": "Node", + "strict": true, + "resolveJsonModule": true, + "isolatedModules": true, + "esModuleInterop": true, + "noEmit": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "skipLibCheck": true + }, + "include": ["src", "index.ts"] +}