|
1 | | -# wallet-adapters |
| 1 | +# @opensea/wallet-adapters |
2 | 2 |
|
3 | | -This repo is bootstrapping. Initial sync from opensea-devtools is in progress. |
| 3 | +Provider-agnostic wallet adapters for signing and sending transactions across managed and local backends. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Provider-agnostic interface** — unified `WalletAdapter` abstraction with capabilities declaration |
| 8 | +- **Managed providers** — Privy, Turnkey, Fireblocks (handle gas/nonce server-side) |
| 9 | +- **Local providers** — PrivateKey (handle gas/nonce client-side via RPC) |
| 10 | +- **Framework bridges** — optional adapters for viem and ethers.js |
| 11 | +- **Zero heavy dependencies** — core uses Web Crypto + `@noble/hashes` / `@noble/curves` |
| 12 | +- **Auto-detection** — `createWalletFromEnv()` picks the right provider from environment variables |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +npm install @opensea/wallet-adapters |
| 18 | +# or |
| 19 | +pnpm add @opensea/wallet-adapters |
| 20 | +``` |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +```ts |
| 25 | +import { createWalletFromEnv } from "@opensea/wallet-adapters" |
| 26 | + |
| 27 | +// Auto-detects provider from environment variables |
| 28 | +// Priority: Privy > Fireblocks > Turnkey > PrivateKey |
| 29 | +const wallet = createWalletFromEnv() |
| 30 | + |
| 31 | +const address = await wallet.getAddress() |
| 32 | +const result = await wallet.sendTransaction({ |
| 33 | + to: "0x...", |
| 34 | + data: "0x...", |
| 35 | + value: "0", |
| 36 | + chainId: 8453, |
| 37 | +}) |
| 38 | +console.log(`TX hash: ${result.hash}`) |
| 39 | +``` |
| 40 | + |
| 41 | +## Adapters |
| 42 | + |
| 43 | +### Privy |
| 44 | + |
| 45 | +Server-side wallet via Privy's API. Handles gas estimation and nonce management. |
| 46 | + |
| 47 | +```ts |
| 48 | +import { PrivyAdapter } from "@opensea/wallet-adapters" |
| 49 | + |
| 50 | +const wallet = PrivyAdapter.fromEnv() |
| 51 | +// Requires: PRIVY_APP_ID, PRIVY_APP_SECRET, PRIVY_WALLET_ID |
| 52 | +``` |
| 53 | + |
| 54 | +### Fireblocks |
| 55 | + |
| 56 | +Enterprise MPC custody via Fireblocks API. |
| 57 | + |
| 58 | +```ts |
| 59 | +import { FireblocksAdapter } from "@opensea/wallet-adapters" |
| 60 | + |
| 61 | +const wallet = FireblocksAdapter.fromEnv() |
| 62 | +// Requires: FIREBLOCKS_API_KEY, FIREBLOCKS_API_SECRET, FIREBLOCKS_VAULT_ID |
| 63 | +``` |
| 64 | + |
| 65 | +### Turnkey |
| 66 | + |
| 67 | +HSM-backed signing with P-256 stamp authentication. |
| 68 | + |
| 69 | +```ts |
| 70 | +import { TurnkeyAdapter } from "@opensea/wallet-adapters" |
| 71 | + |
| 72 | +const wallet = TurnkeyAdapter.fromEnv() |
| 73 | +// Requires: TURNKEY_API_PUBLIC_KEY, TURNKEY_API_PRIVATE_KEY, |
| 74 | +// TURNKEY_ORGANIZATION_ID, TURNKEY_WALLET_ADDRESS, TURNKEY_RPC_URL |
| 75 | +``` |
| 76 | + |
| 77 | +### PrivateKey |
| 78 | + |
| 79 | +Local signing for development and testing. |
| 80 | + |
| 81 | +```ts |
| 82 | +import { PrivateKeyAdapter } from "@opensea/wallet-adapters" |
| 83 | + |
| 84 | +const wallet = PrivateKeyAdapter.fromEnv() |
| 85 | +// Requires: PRIVATE_KEY, RPC_URL |
| 86 | +``` |
| 87 | + |
| 88 | +## Framework Bridges |
| 89 | + |
| 90 | +### viem |
| 91 | + |
| 92 | +```ts |
| 93 | +import { walletAdapterToViemClient } from "@opensea/wallet-adapters/viem" |
| 94 | +import { base } from "viem/chains" |
| 95 | + |
| 96 | +const client = walletAdapterToViemClient(wallet, base, "https://mainnet.base.org") |
| 97 | +// Use as a standard viem WalletClient |
| 98 | +``` |
| 99 | + |
| 100 | +### ethers.js |
| 101 | + |
| 102 | +```ts |
| 103 | +import { walletAdapterToEthersSigner } from "@opensea/wallet-adapters/ethers" |
| 104 | + |
| 105 | +const signer = walletAdapterToEthersSigner(wallet, provider) |
| 106 | +// Use as a standard ethers.js Signer |
| 107 | +``` |
| 108 | + |
| 109 | +## Capabilities |
| 110 | + |
| 111 | +Each adapter declares its capabilities so consumers can check before calling: |
| 112 | + |
| 113 | +```ts |
| 114 | +if (wallet.capabilities.signMessage) { |
| 115 | + const sig = await wallet.signMessage({ message: "hello" }) |
| 116 | +} |
| 117 | + |
| 118 | +if (wallet.capabilities.managedGas) { |
| 119 | + // No need to estimate gas — the provider handles it |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +| Capability | Privy | Fireblocks | Turnkey | PrivateKey | |
| 124 | +|------------|-------|------------|---------|------------| |
| 125 | +| `signMessage` | true | true | true | true | |
| 126 | +| `signTypedData` | true | true | true | true | |
| 127 | +| `managedGas` | true | true | false | false | |
| 128 | +| `managedNonce` | true | true | false | false | |
| 129 | + |
| 130 | +## Observability |
| 131 | + |
| 132 | +Attach hooks for tracing and monitoring: |
| 133 | + |
| 134 | +```ts |
| 135 | +wallet.onRequest = (method, params) => { |
| 136 | + console.log(`→ ${method}`, params) |
| 137 | +} |
| 138 | +wallet.onResponse = (method, result, durationMs) => { |
| 139 | + console.log(`← ${method} (${durationMs}ms)`, result) |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +## License |
| 144 | + |
| 145 | +MIT |
0 commit comments