> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# EVM wallets

> Open a Cloak account from MetaMask, Rabby or Coinbase Wallet, and shield USDC from Base or Polygon

A user with USDC on Base or Polygon can fund a private balance on Solana without a Solana wallet.
`createCloak` takes an EVM wallet, opens the account from its signature, and shields from Base or
Polygon in one call.

## What an EVM wallet can do

| Action | Works | Notes |
| - | - | - |
| Open the Cloak account | Yes | The wallet signs `CLOAK_ACCOUNT_MESSAGE` with `personal_sign` |
| Shield from Base (USDC or ETH) or Polygon (USDC) | Yes | One transfer on that chain; USDC arrives in the private balance |
| Private send, withdrawal, payout | Yes | Signed by the account; the EVM wallet is not asked |
| Shield from Solana | No | Pass a Solana wallet as well |

The signature must be a plain 65-byte key signature. Contract wallets (ERC-1271, ERC-4337) return
something else and are refused. See [Smart wallets](https://docs.cloak.ag/wallets/smart-wallets.md).

## Find the user's EVM wallets

`discoverEvmWallets()` lists the wallets installed in the browser through EIP-6963. Each entry has
`info.name`, `info.icon` and a `provider`. Pass the entry to `createCloak`.

```ts theme={null}
import { createCloak, discoverEvmWallets } from "@cloak.dev/sdk";

const evmWallets = await discoverEvmWallets();
const metamask = evmWallets.find((w) => w.info.name === "MetaMask") ?? evmWallets[0];
if (!metamask) throw new Error("No EVM wallet installed");

const cloak = await createCloak({ wallet: metamask, rpc: process.env.NEXT_PUBLIC_SOLANA_RPC_URL });
console.log(cloak.address, cloak.wallets.map((w) => `${w.name}: ${w.networks.join(", ")}`));
```

`window.ethereum` works too. Pass it as the wallet.

## Shield from Base or Polygon

```ts theme={null}
// Quote first: what arrives at least, and the total fee on the way.
const quote = await cloak.quote({ from: "base", token: "USDC", amount: "6" });
console.log(`at least ${quote.arrives.atLeast} USDC arrives, fee ${quote.fee}`);

const receipt = await cloak.shield({
  from: "base", // or a connected wallet; with an EVM wallet, `chain` picks the network
  token: "USDC",
  amount: "6",
  onProgress: (step) => console.log(step),
});
console.log(receipt.sent, receipt.txs); // "6 USDC", { base: "0x…", solana: "…" }
```

The wallet sends one transfer on Base to a one-time receiving address derived from the account, and
pays Base gas. The SDK shields the USDC when it arrives on Solana. The minimum is about 3 USDC; the
live quote's minimum is the one that counts.

The route holds the money while it is between chains, and refunds an order it cannot fill to the
wallet that sent it. If the page closes mid-way, the money waits at the receiving address and the SDK
shields it on the next start, or when you call `cloak.resume()`. Route guarantees are in
[Cross-chain](https://docs.cloak.ag/guides/cross-chain.md).

## Using both a Solana and an EVM wallet

Pass both. The first that can sign opens the account and the other is linked to it, so either one
opens the same account next time.

```ts theme={null}
import { createCloak, discoverEvmWallets } from "@cloak.dev/sdk";

declare const solanaWallet: unknown; // useWallet(), a Wallet Standard wallet, a Privy wallet

const [evmWallet] = await discoverEvmWallets();
const cloak = await createCloak({ wallets: [solanaWallet, evmWallet], rpc: process.env.NEXT_PUBLIC_SOLANA_RPC_URL });

await cloak.shield({ from: "solana", token: "USDC", amount: "5" }); // signed by the Solana wallet
await cloak.shield({ from: "base", token: "USDC", amount: "5" }); // sent by the EVM wallet
```

## Server-side EVM keys

A viem `WalletClient` or an ethers `Signer` connected to a provider also works, for a backend that
holds an EVM key. A bare key without a connection cannot send; wrap it in a `WalletClient`.

## Errors you will see

| Code | Meaning |
| - | - |
| `route.ambiguous` | An EVM wallet or address was used without saying `chain: "base"` or `"polygon"` |
| `shield.insufficient_funds`, `shield.no_gas` | Checked before anything is reserved: not enough USDC, or no ETH or POL for gas |
| `shield.waiting` | The transfer was sent and has not reached Cloak yet; it finishes on its own |
| `shield.closed` | The route closed the order; `moneyAt` says whether it refunded |
| `wallet.rejected` | The user declined a connect or a signature in the EVM wallet |

## Related

* [Cross-chain](https://docs.cloak.ag/guides/cross-chain.md): every route, minimum and guarantee.
* [Wallet integrations](https://docs.cloak.ag/wallets/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.