cdp-docs-cli
Version:
CLI tool to set up CDP (Coinbase Developer Platform) documentation and integration in your project
106 lines (94 loc) • 3.8 kB
Markdown
# CDP Wallet Quick Context
This file condenses **all wallet-related docs** so the assistant can grasp core concepts without reading individual markdown files.
## SDK & Auth
- Library: `@coinbase/cdp-sdk` (TypeScript) / `cdp-sdk` (Python).
- Required secrets (env):
- `CDP_API_KEY_ID`, `CDP_API_KEY_SECRET` – API key pair created in CDP Portal.
- `CDP_WALLET_SECRET` – Wallet secret enabling signing.
## Account Types
| Type | Networks | Notes |
|------|----------|-------|
| **EOA** | All EVM compatible | Standard private-key account. Pays its own gas. |
| **Smart Account (EIP-4337)** | Base Sepolia/Mainnet | Contract wallet with owner EOA; supports gas sponsorship & batching. One SA per owner. |
| **Solana Account** | Solana mainnet/devnet | Keypair account; signing handled through CDP SDK. |
## Common Operations (TS syntax, mirror in Python)
### Create or fetch account
```ts
const account = await cdp.evm.getOrCreateAccount({ name: 'MyAccount' })
```
### Create Smart Account
```ts
const sa = await cdp.evm.getOrCreateSmartAccount({ owner: account, name: 'MySA' })
```
### Import private key
```ts
await cdp.evm.importAccount({ privateKey: '0xabc…', name: 'Imported' })
```
### Fund with fiat (beta)
```ts
const quote = await account.quoteFund({ network: 'base', token: 'eth', amount: 5n * 10n**14n })
await quote.execute()
```
Or directly:
```ts
await account.fund({ network: 'base', token: 'eth', amount: 500000000000000n })
```
### Request test tokens
```ts
await cdp.evm.requestFaucet({ address: account.address, network: 'base-sepolia', token: 'eth' })
```
### Send transaction
```ts
await cdp.evm.sendTransaction({
address: account.address,
network: 'base-sepolia',
transaction: { to: '0x…', value: parseEther('0.001') }
})
```
### Sign message / hash (Solana & EVM)
```ts
await cdp.solana.signMessage({ address, message: 'hello' })
```
## Managing Accounts
- `listAccounts`, pagination via `pageToken`.
- `updateAccount` allows renaming and attaching `accountPolicy`.
- Portal UI: https://portal.cdp.coinbase.com/products/wallet-api/accounts
## Policies (Governance Engine)
- JSON document with `scope` (`project`|`account`), array `rules`.
- Rule fields: `action` (`accept`|`reject`), `operation` (`signEvmTransaction`, `sendEvmTransaction`, `signEvmMessage`, `signEvmHash`, `signSolTransaction`), `criteria` array.
- Common criteria helpers: `evmAddress` (allow/deny lists), `ethValue`, `evmNetwork`, `evmData` (ABI-aware), `evmMessage` (regex).
- Apply policy:
```ts
const policy = await cdp.policies.createPolicy({ policy: {/* ... */} })
await cdp.evm.updateAccount({ address, update: { accountPolicy: policy.id } })
```
## Import/Export Keys
- Imports supported for:
- EVM private key (hex string)
- Solana private key (base58 or raw 32-byte array)
- Exports require secure enclave; exporting doc currently placeholder.
## Funding (Fiat → Crypto)
- Beta `quoteFund`/`fund` methods; requires Coinbase consumer account w/ US debit card (non-3DS).
- Outputs fees & fiat amount, expiration 10 min.
## Quickstart Workflow
1. **Install**: `npm i @coinbase/cdp-sdk dotenv`.
2. **Env**: add keys to `.env.local`.
3. **Instantiate**: `const cdp = new CdpClient()` (auto-reads env vars).
4. **Create account** → **Faucet** → **Send transaction**.
5. For SA gas sponsorship or base mainnet deployment, read Smart Accounts guide.
6. Use faucets sparingly – see rate limits.
## Useful Links
- Docs home: https://docs.cloud.coinbase.com/wallet-api
- Policy Engine reference: `/api-reference/v2/rest-api/policy-engine/policy-engine`
- Discord: https://discord.com/invite/cdp
This summary should provide enough information for an assistant to implement CDP wallet features without reopening the individual docs.