Skip to content
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

Add app accounts sdk docs #1820

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# App Accounts

App Accounts enable developers to create and manage app-specific accounts for their applications. These accounts are linked to the user's Smart Wallet and can be utilized to sign transactions specifically for the app. This integration grants developers full control over the user experience, ensuring a seamless and cohesive interaction within the app.

## Technical Details

- Smart Wallet Ownership: The user's Smart Wallet acts as an owner of the app account, allowing it to manage and control the app-specific account.
- Key Agnostic: App Accounts are designed to be key agnostic. They leverage our Linked Accounts technology, which supports various key types including in-browser CryptoKeys, Passkeys, and server signer products.

Choose a reason for hiding this comment

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

"Linked Accounts technology" to be eventually replaced with EIP-XXXX?

Choose a reason for hiding this comment

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

including, but not limited to, in-browser CryptoKeys, Passkeys, traditional EOAs, and server wallets products.

Choose a reason for hiding this comment

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

we need a page on different signers types, and the reasons why you as a developer might want to use different ones based your app's use case

- App Accounts can be used to sign transactions, messages, and EIP-712 typed data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# App Accounts

App Accounts enable developers to create and manage app-specific accounts for their applications. These accounts are linked to the user's Smart Wallet and can be utilized to sign transactions specifically for the app. This integration grants developers full control over the user experience, ensuring a seamless and cohesive interaction within the app.

App Accounts can be interacted with via the Coinbase Wallet SDK.

## How it works

1. An application can create an app account for a user by using the `wallet_addAccount` RPC method. See [EIP-XXXX](https://eips.ethereum.org/EIPS/eip-XXXX) for more details.
2. The application can either create the account themselves or provide a signer for the Smart Wallet to create the account.
3. Once the account is created, the application can use the account to sign transactions, messages, and EIP-712 typed data.

## Example (creating a new app account)

```typescript
import { createCoinbaseWalletSDK } from '@coinbase/coinbase-sdk';
import { privateKeyToAccount } from 'viem/accounts';

const sdk = new createCoinbaseWalletSDK({
appName: 'My App',
appLogoUrl: 'https://myapp.com/logo.png',
appChainIds: [84532],
subAccount: {
getSigner: async () => {
return privateKeyToAccount('0x...');
},
},
});

const provider = sdk.getProvider();

const response = await provider.request({
method: 'wallet_addAccount',
params: [
{
version: 1,
account: {
signers: [
{
type: 'key',
data: {
publicKey: '0x...',
type: 'secp256k1',
},
},
{
type: 'account',
data: {
address: '0x...',
},
Comment on lines +47 to +50

Choose a reason for hiding this comment

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

based on what's being passed togetSigner in the SDK above, wouldn't only this provided signer make sense in this example?

},
],
},
},
],
});
```

## Example (using an existing app account)

Choose a reason for hiding this comment

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

using an existing and deployed app account


```typescript
const sdk = new createCoinbaseWalletSDK({
appName: 'My App',
appLogoUrl: 'https://myapp.com/logo.png',
appChainIds: [84532],
subAccount: {
getSigner: async () => {
return privateKeyToAccount('0x...');
},
},
});

const provider = sdk.getProvider();

const response = await provider.request({
method: 'wallet_addAccount',
params: [
{
version: 1,
account: {
address: '0x...',
},
},
],
});
```
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import PreferenceParameters from './preference-parameters.mdx'
import PreferenceParameters from './preference-parameters.mdx';

## Parameters

### appName (optional)

- Type: `string`

The app name. This will be displayed to users on connection, transacting, and signing requests.

### appChainIds (optional)

- Type: `number[]`

Array of chain IDs your app supports. Default value is `[1]`.

[What networks are supported?](/identity/smart-wallet/FAQ#what-networks-are-supported)

### appLogoUrl (optional)

- Type: `string`

App logo image URL. Favicon is used if unspecified.
Expand All @@ -23,4 +26,16 @@ App logo image URL. Favicon is used if unspecified.
Local paths are not supported for `appLogoUrl` as the logo is presented on another window as popup. Please provide a non-local URL.
:::

### subAccount (optional)

- Type: `object`

Subaccount configuration.

#### getSigner

- Type: `function`

Function that returns a signer for the subaccount. This function should resolve to a Viem LocalAccount or a Viem WebAuthnAccount

<PreferenceParameters />
Loading