User: ${this._user} Provider: ${this._prov}
${Object.keys(this._otherUsers).map((u) => { return html`Other user: ${u} Provider: ${this._otherUsers[u]}
` })}Current User: {ctx.user}
Current Provider: {ctx.provider}
{#each Object.entries(ctx.otherUsers) as [key, value]}{key}: {value}
{/each} ``` ## Using Events Listen for [events](/docs/core/jsonrpc.md#events) using lifecycle functions within Svelte components. ```html ``` ## SSR Apps If you are using a framework that uses SSR (server-side rendering) such as SvelteKit, you may need to setup Aioha separately in a `onMount()`. ```htmlCurrent User: {{user}}
Current Provider: {{provider}}
{{key}}: {{value}}
``` Alternatively using Vue's `inject()` function: ```htmlCurrent User: {{user}}
Current Provider: {{provider}}
{{key}}: {{value}}
``` ## Using Events Listen for [events](https://aioha.dev/docs/core/jsonrpc#events) using lifecycle hooks within Vue's composition API. ```html ``` ## SSR Apps If you are using a framework that uses SSR (server-side rendering) such as Nuxt, you may need to setup Aioha separately in a `onMounted()`. ```htmlUser: {user}
Wallet: {wallet}
User: {{ user }}
Wallet: {{ wallet }}
``` Alternatively, use Vue's `inject()` with the exported injection keys: ```html ``` ### SSR Apps For frameworks like Nuxt, initialize Aioha in `onMounted()`. ```htmlUser: {ctx.user}
Wallet: {ctx.wallet}
``` ### SSR Apps For frameworks like SvelteKit, initialize Aioha in `onMount()`. ```htmlUser: ${this._user}
Wallet: ${this._wallet}
` } } ``` > **Note** > > Use `subscribe: true` on `MagiUserCtx` and `MagiWalletCtx` to receive reactive updates when the user or wallet changes. --- # Usage Configure and interact with Magi in 5 minutes or less. ## Instantiation Create an instance of Magi. Returns a `Magi` object. ```js import { Magi } from '@aioha/magi' const magi = new Magi() ``` ## Enums **Wallet:** The `Wallet` enum exported are as follows: ```js export enum Wallet { Hive = 'hive', Ethereum = 'evm', Bitcoin = 'btc', ViewOnly = 'viewonly' } ``` **Asset:** The `Asset` enum exported are as follows: ```js export enum Asset { hive = 'hive', hbd = 'hbd', shbd = 'hbd_savings' } ``` **KeyTypes:** The `KeyTypes` enum exported are as follows: ```js export enum KeyTypes { Posting = 'posting', Active = 'active' } ``` > **Note** > > `KeyTypes` is only applicable for Hive wallets. Ethereum and Bitcoin wallets always sign with the account's key. ## Register Wallets ### Hive Wallet Register a Hive wallet using an [Aioha](https://aioha.dev) instance. ```js import { initAioha } from '@aioha/aioha' const aioha = initAioha() magi.setAioha(aioha) ``` ### Ethereum Wallet Register an Ethereum wallet using a [Viem](https://viem.sh) wallet client. ```js import { createWalletClient, http } from 'viem' const viemClient = createWalletClient({ account: '0xYourAddress', transport: http('https://your-rpc-url') }) magi.setViem(viemClient) ``` ### Bitcoin Wallet Register a Bitcoin wallet by providing a `BtcClient` object. This is a minimal interface that any Bitcoin wallet can implement. ```js import { BtcClient } from '@aioha/magi' ``` The `BtcClient` interface: ```ts interface BtcClient { address: string signMessage(message: string): Promise