Solana
Early Access
The Civic Auth Solana API is subject to change as we continue to develop and refine our solution.
Creating a Wallet
When a new user logs in, they do not yet have a Web3 wallet by default. You can create a wallet for them by calling the createWallet
function on the user object.
Currently, we don’t support connecting users’ existing self-custodial wallets. This is coming soon.
Right now, we only support embedded wallets, which are generated on behalf of the user by our non-custodial wallet partner. Neither Civic nor your app ever has access to the wallets’ private keys.
Here’s a basic example:
Complete examples can be found on Github:
- Vite: with Solana wallet adapter and without Solana wallet adapter
- NextJS with Solana wallet adapter and without Solana wallet adapter
- If you’re using the Solana wallet adapter with NextJS <15.3 and webpack, see this example
The useUser hook and UserContext Object
The useUser hook returns a user context object that provides access to the base library’s user object in the ‘user’ field, and adds some Web3 specific fields. The returned object has different types depending on these cases:
If the user has a wallet,
The wallet object follows the interface used by Solana’s Wallet Adapter.
If the user does not yet have a wallet:
An easy way to distinguish between the two is to use the userHasWallet
type guard.
Using the Wallet
Sending a transaction
Checking the balance
Using the Wallet with the Solana Wallet Adapter
The Civic Auth Web3 SDK uses the Solana Wallet Adapter to expose the embedded wallet to React frontends. This allows you to use familiar hooks such as useWallet
and useConnection
to interact with the wallet.
This means that Civic will be available as a choice for your users to connect when using @solana/wallet-adapter-react
:
In the example above, the user has Phantom installed and can connect their existing Phantom wallets to your dApp via the wallet-adapter. These wallets cannot currently be linked to Civic Auth. When the user selects Civic Auth, they are taken through a social login flow which gives them an embedded wallet generated by our backend, which is then exposed to your dApp via the wallet-adapter interface.
The Civic embedded wallets cannot be connected at the same time as the user’s existing wallets.
Use with Webpack in NextJS
When using the Solana Wallet Adapter with Webpack (default in NextJS <15.3), add the following flag in your next.config.ts or next.config.mjs file, passed into the createCIvicAuthPlugin function:
Make sure to follow the steps described here (React) and here (Next.Js) to get started with the Solana Wallet Adapter.
The Civic Auth Web3 SDK follows the wallet standard, meaning that the Solana Wallet Adapter will automatically discover the embedded wallet.
Set up the Solana Wallet Adapter as shown below:
The above shows a minimal React example. Follow the integration steps to set up the CivicAuthProvider according to your framework.
A Full Example
See below for a full minimal example of a Solana Adapter app using Civic Auth for an embedded wallet.