How to create a USDC wallet

Joan Alavedra3 min read
How to create a USDC wallet

Smart wallets are changing how users interact with digital assets by removing the need to manage private keys or pay for gas in native tokens. In this guide, we'll build a smart wallet that handles USDC transfers with a seamless, fee-sponsored experience.

What is a USDC Wallet?

A USDC wallet is a digital account designed to hold and transfer the USDC stablecoin. By using Openfort’s smart wallet infrastructure, developers can build USDC wallets that don't require users to hold native chain tokens (like ETH or MATIC) for gas fees. Instead, fees can be sponsored by the application or paid directly in USDC using a "paymaster." This makes the wallet feel like a traditional fintech app while keeping the assets secure and non-custodial on-chain.

What we're building

We'll create a "USDC Transfer" application that demonstrates:

  • Embedded Wallet Creation: Using Openfort Shield for secure, non-custodial wallets.
  • Gas Sponsorship: Users pay network fees in USDC or have them fully sponsored.
  • USDC Transfers: Seamless token transfers on the Sepolia testnet.

Prerequisites

Step 1: Bootstrap the Project

We'll start by using gitpick to clone the pre-configured recipe. This gives us a solid foundation with the necessary project structure.


_10
pnpx gitpick openfort-xyz/recipes-hub/tree/main/usdc openfort-usdc
_10
cd openfort-usdc

This sets up a project with:

  • Expo Router for navigation.
  • @openfort/react-native for wallet functionality.
  • Pre-built UI components for onboarding and transfers.

Step 2: Secure Backend Setup

Smart wallets, especially those using Openfort Shield, require a secure backend to handle encryption shares. This ensures that the wallet remains non-custodial and secure.

Clone and run the quickstart backend:


_10
git clone https://github.com/openfort-xyz/openfort-backend-quickstart.git
_10
cd openfort-backend-quickstart
_10
cp .env.example .env
_10
pnpm install
_10
pnpm dev

This local server will handle the protected encryption sessions needed to create and restore the user's wallet.

Step 3: Configure Environment & Policies

To enable gas sponsorship, you need to configure a Policy in your Openfort Dashboard. This policy dictates how gas fees are paid (e.g., sponsored by the app).

  1. Go to the Policies section in the Openfort Dashboard.
  2. Create a new policy for Sepolia (or Base Sepolia).
  3. Copy the Policy ID.

Now, configure your mobile app's environment variables in .env.local:


_10
OPENFORT_PROJECT_PUBLISHABLE_KEY=pk_test_...
_10
OPENFORT_SHIELD_PUBLISHABLE_KEY=pk_test_...
_10
OPENFORT_SHIELD_RECOVERY_BASE_URL=http://localhost:3000
_10
OPENFORT_ETHEREUM_PROVIDER_POLICY_ID=pol_... # Your Policy ID

Step 4: Understanding the Flow

With the setup complete, here is how the Smart Wallet operates:

  1. Authentication: The user logs in (e.g., via email or social).
  2. Wallet Provisioning: The app requests the backend to create an encryption session. The OpenfortProvider then generates the Shield keys on the device.
  3. Transfer: When the user initiates a USDC transfer, the app constructs a UserOperation.
  4. Sponsorship: This operation is sent to Openfort's bundler, which checks the Policy ID. If valid, the gas fees are sponsored.
  5. Execution: The transaction is executed on-chain, and the USDC is transferred.

Conclusion

By leveraging Openfort's infrastructure, you've set up a smart wallet that abstracts away the complexities of gas fees and seed phrases. This provides a familiar experience while maintaining the security and self-custody benefits of on-chain technology.

Check out the full source code to dive deeper into the implementation details.

Share this article

Keep Reading