createSharedState
Usage
connect()
must be called and a connection must be initiated.
The createSharedState()
function creates a shared state account within the user’s wallet and returns the new account’s seed and address.
See Shared State for an overview.
import { createSharedState } from '@puzzlehq/sdk-core';import { useState } from 'react';
export const Page = () => { const [loading, setLoading] = useState(false); const [error, setError] = useState<string | undefined>(); const [sharedStateAccount, setSharedStateAccount] = useState<{ seed: string, address: string} | undefined>();
const onClick = async () => { setLoading(true); setError(undefined); try { const response: CreateSharedStateResponse = await createSharedState(); setSharedStateAccount(response.data); } catch (e) { setError((e as Error).message); } finally { setLoading(false); } }
return ( <div> <button onClick={ onClick } disabled={ loading } > create shared state </button> { sharedStateAccount && ( <div> <p>{'seed: ' + sharedStateAccount.seed}</p> <p>{'address: ' + sharedStateAccount.address}</p> </div> )} { error && <p>error creating shared state: {error}</p> } </div> )}
Types
type CreateSharedStateResponse = { data: { seed: string; address: string; };};