Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions base-account/auto-sub-accounts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Sub Accounts Example

A simple Next.js app demonstrating Base Account SDK Sub Accounts integration with automatic sub account creation and USDC transfers on Base Sepolia.

## Features

- **Automatic Sub Account Creation**: Sub account is created automatically when users connect their wallet
- **USDC Transfer**: Send USDC to a specified address on Base Sepolia
- **Auto Spend Permissions**: Sub accounts can access Universal Account balance when needed
- **Modern UI**: Clean and responsive interface

## Getting Started

### Prerequisites

- Node.js 18+ installed
- A Base Account (create one at [account.base.app](https://account.base.app))
- USDC on Base Sepolia testnet

### Installation

1. Install dependencies:

```bash
npm install
```

2. Run the development server:

```bash
npm run dev
```

3. Open [http://localhost:3000](http://localhost:3000) in your browser

## How It Works

This app uses the **quickstart configuration** from the Base Account SDK:

```tsx
const sdk = createBaseAccountSDK({
subAccounts: {
creation: 'on-connect', // Auto-create sub account on connect
defaultAccount: 'sub', // Use sub account for transactions by default
}
});
```

### Key Benefits

- **No repeated prompts**: Transactions are sent from the sub account without repeated approval
- **Seamless funding**: Auto Spend Permissions allow the sub account to access Universal Account balance
- **Better UX**: Perfect for apps requiring frequent transactions

## Usage

1. **Connect Wallet**: Click "Connect Wallet" and approve the connection in your Base Account
2. **Sub Account Created**: A sub account is automatically created for this app
3. **Send USDC**: Enter an amount and click "Send USDC" to transfer to the recipient address

## Configuration

### Recipient Address

The USDC recipient address is set in `app/page.tsx`:

```tsx
const RECIPIENT_ADDRESS = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
```

### USDC Contract

The app uses the USDC contract on Base Sepolia:

```tsx
const USDC_ADDRESS = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
```

## Learn More

- [Base Account Documentation](https://docs.base.org/base-account)
- [Sub Accounts Guide](https://docs.base.org/base-account/improve-ux/sub-accounts)
- [Base Account SDK](https://github.com/base/account-sdk)

## License

MIT

159 changes: 159 additions & 0 deletions base-account/auto-sub-accounts/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background: linear-gradient(to bottom, #0052ff 0%, #001a66 100%);
min-height: 100vh;
color: white;
}

.container {
max-width: 800px;
margin: 0 auto;
padding: 40px 20px;
}

.card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 16px;
padding: 32px;
margin-bottom: 24px;
border: 1px solid rgba(255, 255, 255, 0.2);
}

.title {
font-size: 2.5rem;
font-weight: bold;
margin-bottom: 8px;
text-align: center;
}

.subtitle {
font-size: 1.1rem;
opacity: 0.9;
text-align: center;
margin-bottom: 32px;
}

.section-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 16px;
}

.info-row {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 16px;
padding: 16px;
background: rgba(0, 0, 0, 0.2);
border-radius: 8px;
}

.info-label {
font-size: 0.875rem;
opacity: 0.8;
font-weight: 500;
}

.info-value {
font-family: 'Monaco', 'Courier New', monospace;
font-size: 0.9rem;
word-break: break-all;
}

.button {
background: white;
color: #0052ff;
border: none;
padding: 14px 28px;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
width: 100%;
margin-bottom: 12px;
}

.button:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

.button:disabled {
opacity: 0.5;
cursor: not-allowed;
}

.button-secondary {
background: transparent;
color: white;
border: 2px solid white;
}

.button-secondary:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.1);
}

.status-message {
padding: 12px 16px;
background: rgba(0, 0, 0, 0.3);
border-radius: 8px;
margin-bottom: 16px;
font-size: 0.9rem;
}

.button-group {
display: flex;
flex-direction: column;
gap: 12px;
}

.input-group {
margin-bottom: 16px;
}

.input-label {
display: block;
margin-bottom: 8px;
font-size: 0.9rem;
font-weight: 500;
}

.input {
width: 100%;
padding: 12px 16px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.3);
background: rgba(0, 0, 0, 0.2);
color: white;
font-size: 1rem;
font-family: 'Monaco', 'Courier New', monospace;
}

.input::placeholder {
color: rgba(255, 255, 255, 0.5);
}

.input:focus {
outline: none;
border-color: white;
}

20 changes: 20 additions & 0 deletions base-account/auto-sub-accounts/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Metadata } from "next";
import "./globals.css";

export const metadata: Metadata = {
title: "Sub Accounts Example",
description: "Demo app showing Base Account Sub Accounts integration",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}

Loading