Skip to content

Updating Base Account Reference section #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 31, 2025
Merged

Updating Base Account Reference section #150

merged 12 commits into from
Jul 31, 2025

Conversation

youssefea
Copy link
Contributor

@youssefea youssefea commented Jul 29, 2025

What changed? Why?

  • Restructure Reference section (Account SDK, Provider, UI Elements, Onchain Contracts)
  • Expose all of the RPC methods and Capabilities
  • Add 'createBaseAccountSDK' reference
  • Add multiple capabilities and RPC methods
  • Update the Overview page of the Provider sub section

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jul 29, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

ericbrown99
ericbrown99 previously approved these changes Jul 30, 2025
Comment on lines 141 to 149
{
success: false,
error: "Insufficient balance",
amount: "10.50",
to: "0x1234567890123456789012345678901234567890"
}
```
</ResponseExample>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spencerstock has an ongoing PR to throw errors instead of returning typed responses base/account-sdk#71

Let's hold off on this section until the PR is resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this now and update when Spencer merges his PR

Comment on lines 120 to 335
- Session expired

Always wrap calls in a try-catch block:

```typescript
async function safeGetAccount() {
try {
const cryptoAccount = await getCryptoKeyAccount();
return cryptoAccount?.account;
} catch (error) {
console.error('Error getting crypto account:', error);

if (error.message.includes('not initialized')) {
// SDK not properly initialized
throw new Error('Base Account SDK not initialized');
} else if (error.message.includes('permission denied')) {
// User denied access
throw new Error('User denied account access');
} else if (error.message.includes('session expired')) {
// Session needs refresh
throw new Error('Session expired, please reconnect');
} else {
// Unknown error
throw new Error('Failed to access account');
}
}
}
```

## Real-time Account Updates

```typescript
import { getCryptoKeyAccount } from '@base-org/account';

class AccountMonitor {
private account: WebAuthnAccount | LocalAccount | null = null;
private listeners: ((account: any) => void)[] = [];
private pollInterval: NodeJS.Timeout | null = null;

async start() {
// Initial check
await this.checkAccount();

// Poll for changes every 5 seconds
this.pollInterval = setInterval(() => {
this.checkAccount();
}, 5000);
}

stop() {
if (this.pollInterval) {
clearInterval(this.pollInterval);
this.pollInterval = null;
}
}

private async checkAccount() {
try {
const cryptoAccount = await getCryptoKeyAccount();
const newAccount = cryptoAccount?.account;

// Check if account changed
if (newAccount?.address !== this.account?.address) {
const previousAccount = this.account;
this.account = newAccount;

// Notify listeners
this.listeners.forEach(listener => {
listener({
previous: previousAccount,
current: newAccount
});
});
}
} catch (error) {
console.error('Error monitoring account:', error);
}
}

onAccountChange(listener: (account: any) => void) {
this.listeners.push(listener);
}

getCurrentAccount() {
return this.account;
}
}
```

## Best Practices

1. **Check for null returns**: Always check if account exists before using
2. **Handle errors gracefully**: Wrap calls in try-catch blocks
3. **Cache results**: Avoid excessive calls by caching account information
4. **Monitor changes**: Implement account change detection for better UX
5. **Validate data**: Always verify account data integrity

import PolicyBanner from "/snippets/PolicyBanner.mdx";

<PolicyBanner />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's delete section, this library is meant to be used to manage sub account signers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted, thanks

Comment on lines 69 to 74
| Code | Message | Description |
| ---- | ------- | ----------- |
| 4100 | Storage access denied | Cannot access secure key storage |
| 4200 | Storage corruption | Stored key data is corrupted or invalid |
| 4300 | Browser compatibility | Browser does not support required storage APIs |

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the AI is hallucinating here, we don't throw these error codes.

}
```

## Integration with Account Management
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reframe this section as maybe "usage example". I don't want to confuse devs that this is how we want them to do base account account management, since this is not what this library is used for (it's for managing sub account local signers)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed it

```typescript Success Response (WebAuthn Account)
{
account: {
address: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
address: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",

Copy link
Contributor

@stephancill stephancill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

}
```

```json signInWithEthereum Response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should consider just linking out to the SIWE capability page so that we don't have to maintain this in two places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree - removed from there for now and added linking to the capability

Defined in the [Base Account SDK](https://github.com/base/account-sdk)

<Info>
Retrieves the current crypto account associated with the user's session. This is the primary function for accessing account information in Base Account applications.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finding this hard to understand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Defined in the [Base Account SDK](https://github.com/base/account-sdk)

<Info>
Retrieves an existing P256 key pair if one has been previously generated and stored. This is useful for checking if keys already exist before generating new ones.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we maybe combine this, getCryptoKeyAccount, and generateKeyPair into a single page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will take a look at this in a next PR

@cb-heimdall cb-heimdall dismissed ericbrown99’s stale review July 30, 2025 15:43

Approved review 3071896399 from ericbrown99 is now dismissed due to new commit. Re-request for approval.

@youssefea youssefea merged commit e1a71ee into master Jul 31, 2025
7 checks passed
@youssefea youssefea deleted the update-reference branch July 31, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants