@cryptopuppie/svelte-wax-auth
v0.0.1
Published
WAX authentication for Svelte apps.
Downloads
2
Readme
svelte-wax-auth
WAX authentication for Svelte apps.
Install
pnpm add @cryptopuppie/svelte-wax-auth
Usage
<script>
import WaxAuthProvider from '@cryptopuppie/svelte-wax-auth';
const endpoint = 'https://waxtestnet.greymass.com';
const chainId = 'f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12';
const dApp = 'wax-auth-demo';
</script>
<WaxAuthProvider {...{ endpoint, chainId, dApp }}>
<slot />
</WaxAuthProvider>
<script lang="ts">
import { getAuthContext } from '@cryptopuppie/svelte-wax-auth/context';
const { user, isLoggedIn, loginWithAnchor, logout } = getAuthContext();
const testTransact = async () => {
if (!$user) return;
await $user
.transact(
[
{
account: 'eosio.token',
name: 'transfer',
authorization: [
{
actor: $user.wallet,
permission: $user.permission
}
],
data: {
from: $user.wallet,
to: 'eosio',
quantity: '0.00000001 WAX',
memo: ''
}
}
],
{ blocksBehind: 3, expireSeconds: 1200 }
)
.then((r) => {
console.log(r);
});
};
</script>
<div>
{#if $isLoggedIn}
<button on:click={logout}>logout</button>
<button on:click={testTransact}>test transaction</button>
{:else}
<button on:click={loginWithAnchor}>login with anchor</button>
{/if}
<p>{$user?.wallet}</p>
</div>
© 2022 | World of Cryptopups