Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monorepo: Add Browser Examples #2835

Merged
merged 20 commits into from
Jun 28, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add Blockchain browser example
holgerd77 committed Jun 28, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit 73374c0514ed28044a7a7dbd4eafbd465682664a
56 changes: 56 additions & 0 deletions packages/blockchain/examples/browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!doctype html>
<html>

<head>
<title>EthereumJS Browser Examples</title>
<script type="module">
import { Blockchain } from '@ethereumjs/blockchain'
import { bytesToPrefixedHexString } from '@ethereumjs/util'

const run = async () => {
const blockchain = await Blockchain.create()
const head = await blockchain.getIteratorHead()
console.log(bytesToPrefixedHexString(head.hash()))
}

run()
</script>

</head>

<body style="padding:50px; font-family: Arial, Helvetica, sans-serif;">
<h1>Blockchain | @ethereumjs/blockchain</h1>
Basic usage of this library in the browser (using <a href="https://github.com/vitejs/vite" target="_blank">Vite</a>)

<h3>Run the Example</h3>
<ol>
<li>
Go to the library root directory (packages/[LIBRARY_NAME]/)
</li>
<li>
Build "dist" folder with: npm run build
</li>
<li>
Start Vite development server with: npx vite
</li>
<li>
Open the example URL in the browser (http://localhost:5173/examples/browser.html)
</li>
<li>
Open the development console (e.g. Chrome Developer Tools)
</li>
<li>
See example results and play with the code
</li>
</ol>

<h3>Interactive CLI</h3>
<ol>
<li>Open the "Sources -> Page" tab in the Chrome Developer Tools</li>
<li>Set a breakpoint within the original "browser.html" file (so not the one generated by Vite)</li>
<li>Now you can use and play with the imports dynamically</li>
</ol>

</body>

</html>
2 changes: 1 addition & 1 deletion packages/trie/examples/browser.html
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

const trie = new Trie()

async function test() {
const test = async () => {
await trie.put(utf8ToBytes('test'), utf8ToBytes('one'))
const value = await trie.get(utf8ToBytes('test'))
console.log(bytesToUtf8(value)) // 'one'