# GemWallet Compatibility

Run a dApp built on GemWallet's API against Joey by changing one import.

`@joeywallet/gemwallet-compat` implements GemWallet's `@gemwallet/api` interface (matching version 3.8.0) on top of Joey.

## Install

```bash
npm install @joeywallet/gemwallet-compat
```

It's released with the same version number as `@joeywallet/wallet-sdk`.

## Migrate

```diff
- import { isInstalled, getAddress, sendPayment } from '@gemwallet/api'
+ import { isInstalled, getAddress, sendPayment } from '@joeywallet/gemwallet-compat'
```

> [!NOTE]
> Joey doesn't pretend to be GemWallet in the page (there's no `window.gemWallet`). Your dApp has to import this package for GemWallet-style code to reach Joey.

Results use GemWallet's `{ type: 'response' | 'reject', result }` envelope, so existing `result.type === 'reject'` checks keep working. GemWallet's field names (for example `fee`, `sequence` and `memos: [{ memo: { memoData } }]`) are converted to XRPL field names for you.

## Supported functions

| Function | Behaviour |
|---|---|
| `isInstalled()` | `{ result: { isInstalled } }`. Never rejects; waits up to 1 second, like GemWallet. |
| `getAddress()` | Reconnects silently if possible, otherwise prompts. Returns `{ address }`. |
| `getPublicKey()` | `{ address, publicKey }`. Fails for watch-only accounts. |
| `getNetwork()` | `{ chain: 'XRPL', network: 'Mainnet' \| 'Testnet' \| 'Devnet', websocket }` |
| `sendPayment(payload)` | Builds a `Payment`, signs and submits it. Returns `{ hash }`. |
| `setTrustline(payload)` | Builds a `TrustSet`, signs and submits it. Returns `{ hash }`. |
| `signTransaction({ transaction })` | `{ signature }`: the signed transaction blob, as in GemWallet |
| `submitTransaction({ transaction })` | `{ hash }` |
| `submitBulkTransactions({ transactions })` | `{ transactions: [{ id?, accepted, hash? }] }`. Always stops at the first failure (`onError` is ignored). |
| `on(event, callback)` | `login`, `logout`, `networkChanged` and `walletChanged`. Returns an unsubscribe function. |

## Not supported

These throw `GemWalletUnsupportedError` (code `4200`) immediately:

- `setRegularKey()`, `setHook()` and `setAccount()`: Joey refuses account-control operations from dApps. See [Supported transactions](/docs/browser-extension/transactions).
- `signMessage()`: use the SDK's [`signIn()`](/docs/browser-extension/sign-in) instead.

GemWallet's NFT and offer helpers (`mintNFT`, `createOffer` and similar) aren't included. Build those transactions yourself and send them with `submitTransaction`, or use the SDK directly.
