Skip to main content

Class: SiweSession

Sign-In With Ethereum sessions, i.e., SiweSessions, implement the Session interface.

Privy's backend is able to issue access tokens using the Sign-In With Ethereum spec. This enables developers to use Privy for reading/writing user data without hosting their own backend to handle authentication. A big win for reducing operational complexity!

import {SiweSession} from '@privy-io/privy-browser';

Hierarchyโ€‹

Constructorsโ€‹

constructorโ€‹

โ€ข new SiweSession(apiKey, provider, options?)

Parametersโ€‹

NameTypeDescription
apiKeystringYour public API key.
providerEthereumProviderThe Ethereum provider, typically window.ethereum (injected by MetaMask).
options?HTTPOptionsInitialization options.

Overridesโ€‹

CustomSession.constructor

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/siwe.ts:95

Propertiesโ€‹

tokenโ€‹

โ€ข token: null | string = null

JWT returned by the Privy API upon successfully authenticating.

Inherited fromโ€‹

CustomSession.token

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/custom.ts:30

Methodsโ€‹

addressโ€‹

โ–ธ address(): Promise<null | string>

The currently connected address.

Returnsโ€‹

Promise<null | string>

EIP-55 mixed-case checksum-encoded address or null if not connected.

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/siwe.ts:134


authenticateโ€‹

โ–ธ authenticate(): Promise<void>

Authenticate the session.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

CustomSession.authenticate

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/custom.ts:82


chainIdโ€‹

โ–ธ chainId(): Promise<string>

The currently connected EIP-155 chain id. E.g., 1 for Ethereum mainnet.

Returnsโ€‹

Promise<string>

The EIP-155 chain id.

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/siwe.ts:155


connectโ€‹

โ–ธ connect(): Promise<null | string>

Prompt the user to connect their wallet.

Returnsโ€‹

Promise<null | string>

EIP-55 mixed-case checksum-encoded address of connected wallet or null if user does not connect.

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/siwe.ts:145


destroyโ€‹

โ–ธ destroy(): Promise<void>

Destroy the session.

Returnsโ€‹

Promise<void>

Inherited fromโ€‹

CustomSession.destroy

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/custom.ts:89


isAuthenticatedโ€‹

โ–ธ isAuthenticated(): Promise<boolean>

A Session is considered authenticated if there is a valid token and the connected wallet address is the same as the token subject.

Returnsโ€‹

Promise<boolean>

Whether or not the session is considered authenticated.

Overridesโ€‹

CustomSession.isAuthenticated

Defined inโ€‹

privy-js/packages/privy-browser/src/sessions/siwe.ts:114