Moso Auth SDK comes with two ways to use. Inline via /dist/web/index.js or import from the npm package.
// import via script tag dist/web/index.js
const authorization = window.moso_auth.initialize({
api: {
key: "<your_api_key>",
url: "https://api.moso.xyz"
},
appName: "Sample App",
chains: ["arbitrum", "base", "mainnet", "optimism", "polygon"],
clientId: "<your_client_key>",
projectId: "your_project_key",
walletGroups: [{
name: "Group Name",
wallets: ["bitgetWallet", "coinbaseWallet", "metaMaskWallet", "okxWallet", "trustWallet"]
}]
});
-- OR --
import { auth } from '@mosohq/auth-sdk';
const authorization = auth.initialize({
api: {
key: "<your_api_key>",
url: "https://api.moso.xyz"
},
appName: "Sample App",
chains: ["arbitrum", "base", "mainnet", "optimism", "polygon"],
clientId: "<your_client_key>",
projectId: "your_project_key",
walletGroups: [{
name: "Group Name",
wallets: ["bitgetWallet", "coinbaseWallet", "metaMaskWallet", "okxWallet", "trustWallet"]
}]
});
authorization.login(): void;
authorization.openAccountModal(): void;
authorization.getState(callback: (state: AuthState) => void): void;
// NOTE: onStateChange returns an unsubscribe method to stop subscribing to changes
// It is also overloaded, see below
authorization.onStateChange(callback: (state: AuthState) => void): () => void;
// NOTE: You can listen for only specific property changes authorization.onStateChange("isConnected", (value) => {});
authorization.onStateChange<T extends keyof AuthState>(key: T, callback: (state: AuthState[T]) => void): () => void;
authorization.logout(): void;
authorization.signMessage(callback: (value: SignedTransactionResponse) => void): void
authorization.createToken(options: CreateTokenOptions, callback: (token: string) => void): void
type AuthState = {
connectModalOpen: boolean;
accountModalOpen: boolean;
address: `0x${string}` | undefined,
addresses: readonly [`0x${string}`, ...`0x${string}`[]] | readonly `0x${string}`[] | undefined;
isConnected: boolean;
isConnecting: boolean;
chainId: number | undefined;
isDisconnected: boolean;
isReconnecting: boolean;
status: "connected" | "connecting" | "disconnected" | "reconnecting" | "pending-signature";
}
type SignedTransactionResponse = {
message: string;
signedTransaction: string;
}
type CreateTokenOptions = {
signedTransaction: string;
message: string;
claims?: Record<string, string>;
}