3.0 KiB
3.0 KiB
Coinbase Smart Wallet
The toCoinbaseSmartAccount implementation references the Coinbase Smart Wallet contract.
Usage
:::code-group
import { toCoinbaseSmartAccount } from 'viem/account-abstraction' // [!code focus]
import { client } from './client.js'
import { owner } from './owner.js'
const account = await toCoinbaseSmartAccount({ // [!code focus]
client, // [!code focus]
owners: [owner], // [!code focus]
version: '1.1', // [!code focus]
}) // [!code focus]
import { http, createPublicClient } from 'viem'
import { mainnet } from 'viem/chains'
export const client = createPublicClient({
chain: mainnet,
transport: http(),
})
import { privateKeyToAccount } from 'viem/accounts'
export const owner = privateKeyToAccount('0x...')
import { createWebAuthnCredential, toWebAuthnAccount } from 'viem/account-abstraction'
// Register a credential (ie. passkey).
const credential = await createWebAuthnCredential({ name: 'Wallet' })
// Create a WebAuthn owner account from the credential.
export const owner = toWebAuthnAccount({ credential })
:::
:::tip Tip: You can use a Passkey (WebAuthn) to sign User Operations. Check the owner.ts (Passkey) tab. :::
Returns
SmartAccount<CoinbaseSmartAccountImplementation>
Parameters
client
- Type:
Client
Client used to retrieve Smart Account data.
const client = createPublicClient({ // [!code focus]
chain: mainnet, // [!code focus]
transport: http(), // [!code focus]
}) // [!code focus]
const account = await toCoinbaseSmartAccount({
client, // [!code focus]
owners: [owner],
version: '1.1',
})
owners
- Type:
(LocalAccount | WebAuthnAccount)[]
Owners of the Smart Account. Can be a Local Account or a WebAuthn Account (Passkey).
const account = await toCoinbaseSmartAccount({
client,
owners: [privateKeyToAccount('0x...')], // [!code focus]
})
ownerIndex (optional)
- Type:
number
Index of the owner to use for signing messages & User Operations.
const account = await toCoinbaseSmartAccount({
client,
owners: [privateKeyToAccount('0x...'), privateKeyToAccount('0x...')],
ownerIndex: 1, // [!code focus]
version: '1.1',
})
nonce (optional)
- Type:
bigint
Nonce to use for the Smart Account.
const account = await toCoinbaseSmartAccount({
client,
owners: [owner],
nonce: 1n, // [!code focus]
version: '1.1',
})
version
- Type:
'1.1' | '1' - Default:
'1'
Version of the Smart Account to use.
:::warning Version bumps DO contain breaking changes. :::
const account = await toCoinbaseSmartAccount({
client,
owners: [owner],
version: '1', // [!code focus]
})