> Source: https://developers.terrawallet.us/docs/connect/eip-6963 . Terra Wallet developer docs (early access).

# EIP-6963 and EIP-1193

The Terra Wallet extension injects a standard EIP-1193 provider and announces it through EIP-6963. The Terra
Wallet app's dApp browser injects EVM and Solana providers too. This works today with no Terra SDK.

## Discover Terra Wallet (EIP-6963)

EIP-6963 lets several wallets announce themselves without fighting over `window.ethereum`. Listen for
announcements, then ask wallets to announce:

```js
// Works today: find Terra Wallet through EIP-6963.
const wallets = new Map();
window.addEventListener("eip6963:announceProvider", (event) => {
  wallets.set(event.detail.info.uuid, event.detail);
});
window.dispatchEvent(new Event("eip6963:requestProvider"));

export function findTerraWallet() {
  return [...wallets.values()].find((w) => w.info.rdns === "com.terrawallet.app") ?? null;
}
```

Each announcement carries `info` (`uuid`, `name`, `icon`, `rdns`) and `provider` (EIP-1193). Terra Wallet's
`rdns` is `com.terrawallet.app`. Show the wallet's own `info.name` and `info.icon` in your wallet picker.

## Connect (EIP-1193)

Ask for accounts from a user action such as a click:

```js
async function connectTerraWallet() {
  const terra = findTerraWallet();
  if (!terra) throw new Error("Terra Wallet is not installed");
  const [account] = await terra.provider.request({ method: "eth_requestAccounts" });
  const chainId = await terra.provider.request({ method: "eth_chainId" }); // hex, for example "0x1"
  return { provider: terra.provider, account, chainId };
}
```

Listen for changes:

```js
terra.provider.on("accountsChanged", (accounts) => { /* empty array: disconnected */ });
terra.provider.on("chainChanged", (chainIdHex) => { /* reload chain-specific state */ });
```

## Sign a message

Use `personal_sign` for login messages, ideally in the Sign-In with Ethereum (EIP-4361) format, and
`eth_signTypedData_v4` for structured data. `eth_sign` is disabled.

```js
const message = `shop.example.com wants you to sign in with your account:\n${account}\n\nNonce: ${nonce}`;
const signature = await terra.provider.request({
  method: "personal_sign",
  params: [message, account],
});
// Send { message, signature } to your server and verify it there.
```

Server-side verification samples (Node and Python) are available from the MCP tool `get_code_sample` with
`product: "connect"`.

## Switch chains

```js
await terra.provider.request({
  method: "wallet_switchEthereumChain",
  params: [{ chainId: "0x2105" }], // Base (8453)
});
```

Terra Wallet connects dApps on Ethereum, BNB Smart Chain, Polygon, Avalanche, Arbitrum, Optimism, Base and
Fantom (chain ids in [Supported networks and assets](https://developers.terrawallet.us/docs/networks.md)). Handle error code `4902` (unknown chain)
and `4001` (the user rejected the request).

## Solana

Terra Wallet registers a Solana Wallet Standard wallet named "Terra Wallet", so Solana dApps that use the
Wallet Standard (for example through the Solana wallet-adapter) list it automatically. A legacy `window.solana`
provider is also available.

## Errors to handle

| Code | Meaning |
|---|---|
| `4001` | The user rejected the request |
| `4100` | The account or method is not authorized yet: connect first |
| `4200` | The method is not supported (for example `eth_sign`) |
| `4902` | The chain is not known to the wallet |
