-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
264 additions
and
5 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,3 @@ | ||
# _REPLACE ME_ Example | ||
|
||
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github.com/iosh/cive/tree/main/examples/logs_block_event_logs) |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<h1 class="title has-text-centered">Block event logs Example</h1> | ||
<div class="container" id="app">Loading...</div> | ||
<script type="module"> | ||
import './index.tsx'; | ||
</script> | ||
</body> | ||
</html> |
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,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './src/App' | ||
import 'bulma/css/bulma.css' | ||
ReactDOM.createRoot(document.getElementById('app') as HTMLElement).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) |
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,21 @@ | ||
{ | ||
"name": "logs_block_event_logs", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite" | ||
}, | ||
"dependencies": { | ||
"bulma": "^1.0.2", | ||
"cive": "latest", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.3.8", | ||
"@types/react-dom": "^18.3.0", | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"typescript": "^5.6.2", | ||
"vite": "^5.4.4" | ||
} | ||
} |
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,83 @@ | ||
import { http, createPublicClient } from 'cive' | ||
import { mainnet } from 'cive/chains' | ||
import { useCallback, useState } from 'react' | ||
|
||
const client = createPublicClient({ | ||
chain: mainnet, | ||
transport: http(), | ||
}) | ||
export default function App() { | ||
const [logs, setLogs] = useState('') | ||
|
||
const handleClick = useCallback(async () => { | ||
const epochNumber = await client.getEpochNumber() | ||
const logs = await client.getLogs({ | ||
fromEpoch: epochNumber - 10n, | ||
toEpoch: epochNumber, | ||
}) | ||
setLogs( | ||
JSON.stringify( | ||
logs, | ||
(_, value) => (typeof value === 'bigint' ? value.toString() : value), | ||
2, | ||
), | ||
) | ||
}, []) | ||
|
||
const handleGetLogsWithEvent = useCallback(async () => { | ||
const epochNumber = await client.getEpochNumber() | ||
const logs = await client.getLogs({ | ||
fromEpoch: epochNumber - 50n, | ||
toEpoch: epochNumber, | ||
events: [ | ||
{ | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'from', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Transfer', | ||
type: 'event', | ||
}, | ||
] as const, | ||
}) | ||
setLogs( | ||
JSON.stringify( | ||
logs, | ||
(_, value) => (typeof value === 'bigint' ? value.toString() : value), | ||
2, | ||
), | ||
) | ||
}, []) | ||
|
||
return ( | ||
<div className="box"> | ||
<div className="columns is-3 "> | ||
<div className="column"> | ||
<button className="button" onClick={handleClick}> | ||
Get 10 epoch logs | ||
</button> | ||
|
||
<button className="button" onClick={handleGetLogsWithEvent}> | ||
Get Transfer event logs by 50 epoch | ||
</button> | ||
<pre className="is-size-5"> | ||
<code>{logs}</code> | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"] | ||
} |
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,7 @@ | ||
import react from '@vitejs/plugin-react' | ||
import { defineConfig } from 'vite' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.