Privy is a third-party service that allows users to login using their email or social accounts (Google, Facebook, Twitter, etc). Upon login, a NEAR wallet is created for the user, which they can fund and use to interact with your dApp.Documentation Index
Fetch the complete documentation index at: https://docs.near.org/llms.txt
Use this file to discover all available pages before exploring further.
See full working example here
Web3Auth
For an alternative social login method you can check Web3Auth. We have a functional Web3Auth Integration Example to show how to integrate Web3Auth into your web app.
Installation
Setting Up the Providers
Wrap your application withPrivyProvider and a custom NEARxPrivy context that bridges Privy’s authentication with a NEAR account:
Getting a Privy App ID
Getting a Privy App ID
- Sign up at privy.io and create a new app.
- Copy the App ID from the dashboard and set it as your
appIdprop. - Configure allowed login methods and any other settings in the Privy dashboard.
NEAR Context
TheNEARxPrivy provider listens to Privy’s authentication state. Once the user is logged in, it creates a NEAR wallet (if one doesn’t exist yet) and exposes a nearAccount instance through context:
| Value | Type | Description |
|---|---|---|
walletId | string | The user’s NEAR account address |
nearAccount | Account | A @near-js/accounts Account ready to sign transactions |
provider | JsonRpcProvider | A read-only RPC provider to query the network |
Custom Signer
Privy signs transactions through its embedded wallet viasignRawHash. The privySigner class adapts that API to the interface expected by @near-js/accounts:
Signing In / Out
UseuseLogin and useLogout from Privy to open the login modal and sign the user out:
Calling Read-only Methods
Use theprovider from context to call view methods — no login required:
Calling Change Methods
Use thenearAccount from context to call change methods. The transaction is signed silently by Privy’s embedded wallet, providing a Web2-like UX: