Skip to content

Commit

Permalink
feat: add SignMessage component to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteAtATime committed Oct 31, 2024
1 parent e3ae569 commit 1e98452
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BlockNumber from './_components/BlockNumber.svelte'
import Connect from './_components/Connect.svelte'
import Connections from './_components/Connections.svelte'
import ReadContract from './_components/ReadContract.svelte'
import SignMessage from './_components/SignMessage.svelte'
import SwitchAccount from './_components/SwitchAccount.svelte'
import SwitchChain from './_components/SwitchChain.svelte'
</script>
Expand All @@ -17,3 +18,4 @@ import SwitchChain from './_components/SwitchChain.svelte'
<SwitchChain />
<Connections />
<ReadContract />
<SignMessage />
23 changes: 23 additions & 0 deletions packages/svelte/src/routes/_components/SignMessage.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import { useSignMessage } from '$lib/hooks/useSignMessage.svelte.js'
import type { SignableMessage } from 'viem'
const { data, signMessage } = $derived.by(useSignMessage())
function handleSubmit(event: SubmitEvent) {
event.preventDefault()
const formData = new FormData(event.target as HTMLFormElement)
signMessage({ message: formData.get('message') as SignableMessage })
}
</script>

<h2>Sign Message</h2>

<form onsubmit={handleSubmit}>
<input name="message" />
<button type="submit">Sign Message</button>
</form>

{#if data}
{data}
{/if}

0 comments on commit 1e98452

Please sign in to comment.