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 thecreateWallet
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.You could use Civic’s
embeddedWallet()
wagmi connector alongside other connectors like Metamask, so your code can switch between Civic embedded wallets and the user’s other installed wallets. Currently those wallets cannot be linked to the Civic account, they are separate.Neither Civic nor your app ever has access to the wallets’ private keys.Complete examples can be found on github:
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,userHasWallet
type guard.
Using the Wallet
The Civic Auth Web3 SDK uses Wagmi and Viem to expose the embedded wallet to your app, simplifying wallet interactions on both the front end and back end.- React Apps: Civic Auth is optimized for React, with easy access to Wagmi hooks for a seamless experience.
- Non-React Apps: For non-React frameworks, use Viem directly to interact with the wallet.
Using the Wallet with Wagmi
To use the embedded wallet with Wagmi, follow these steps:PrerequisitesFollow the Wagmi documentation to learn how to set up your app with Wagmi.Ensure you have created the user’s wallet first as described above.
1. Add the Embedded Wallet to Wagmi Config
IncludeembeddedWallet()
in your Wagmi configuration as shown below:
2. Connect the wallet
Autoconnect
If you want to automatically connect the civic wallet as soon as the user has logged in, you can use theuseAutoConnect()
hook:
Manual
If you want a little more control, first create the wallet,connect
method.
3. Use Wagmi Hooks
Once connected, you can use Wagmi hooks to interact with the embedded wallet. Common hooks include:-
useBalance
: Retrieve the wallet balance. -
useAccount
: Access account details. -
useSendTransaction
: Send transactions from the wallet. -
useSignMessage
: Sign messages with the wallet.
A Full Example
See below for a full minimal example of a Wagmi app using Civic Auth for an embedded wallet. This is based on this GitHub repository that contains a sample implementation.Using the Wallet with Viem
If you are not using Wagmi, you may also use Viem directly to access the same wallet capabilities:Using Viem without React
Our SDK is currently being adapted to support other frontend frameworks beyond React. Contact Civic in our developer community if you have questions about integrating Civic Auth Web3 with a different framework.Configuration
The library works out of the box without additional configuration. If you need to customize the library’s behavior, you can pass additional configuration options to theCivicAuthProvider
component. Here is an example:
Supported EVM Chains
Civic Auth embedded wallets support the following EVM-compatible blockchain networks:Ethereum
Mainnet and testnets
Base
Coinbase Layer 2
Polygon
MATIC ecosystem
BSC (BNB)
Binance Smart Chain
Arbitrum One
Ethereum Layer 2
Avalanche
AVAX C-Chain
Unichain
Uniswap Layer 2
Sonic
High-speed blockchain
Cronos
Crypto.com Chain
OP Mainnet
Optimism Layer 2
Linea
ConsenSys zkEVM
ZKSync Era
Matter Labs zkEVM
Filecoin
Decentralized storage
Gnosis
Community-driven chain
Rootstock
Bitcoin sidechain
Mantle
Modular Layer 2
Ronin
Gaming-focused sidechain
Celo
Mobile-first blockchain
All supported chains are EVM-compatible, meaning you can use the same wallet address across all of them.
Limiting to specific chains
By default, Civic Auth supports all chains supported by viem. If you want to restrict wallet usage to specific chains, you can pass an array of chains to the CivicAuthProvider. Pass theinitialChain
property to define the chain you want to start using.