Skip to content

Commit

Permalink
Merge branch 'main' into logs_pending_transactions_example
Browse files Browse the repository at this point in the history
  • Loading branch information
typicalHuman committed Feb 3, 2024
2 parents 924e779 + efec0bd commit 78d2fde
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/logs_pending_transactions/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" />
</head>
<body>
<h1>Pending Transactions Example</h1>
<div id="app">Loading...</div>
<script type="module" src="./index.ts"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/logs_pending_transactions/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}
},
});
15 changes: 15 additions & 0 deletions examples/logs_pending_transactions/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions examples/logs_pending_transactions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 78d2fde

Please sign in to comment.