> For the complete documentation index, see [llms.txt](https://docs.minervachain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.minervachain.org/build/dapp-integration.md). Agents can also search and read this documentation through its [MCP server](https://docs.minervachain.org/~gitbook/mcp).

# Integrate a dapp

Minerva Wallet's browser extension injects an EIP-1193 provider and announces itself through EIP-6963, so a dapp built for Ethereum wallets connects with the usual code. What changes is what happens when the user signs.

## Detect the wallet

```ts
// EIP-6963: listen for provider announcements
window.addEventListener("eip6963:announceProvider", (event) => {
  const { info, provider } = event.detail;
  if (info.rdns === "org.minerva.wallet") useProvider(provider);
});
window.dispatchEvent(new Event("eip6963:requestProvider"));

// Legacy fallback
const provider = window.ethereum;
```

Libraries such as wagmi and viem pick the extension up automatically through EIP-6963.

## Connect and read the chain

```ts
const [address] = await provider.request({ method: "eth_requestAccounts" });
const chainId = await provider.request({ method: "eth_chainId" }); // "0x12d53" mainnet, "0x12d52" testnet
```

The first `eth_requestAccounts` opens the wallet's connection prompt; the user picks the account to share. Read methods (`eth_call`, `eth_getBalance`, `eth_getLogs`, …) pass straight through to the active network's RPC.

## Switch networks

```ts
await provider.request({
  method: "wallet_switchEthereumChain",
  params: [{ chainId: "0x12d53" }],   // or "0x12d52" for the testnet
});
```

The extension accepts both built-in networks and emits `chainChanged` to every connected site. Requesting any other chain id returns error 4902. `wallet_addEthereumChain` with a Minerva chain id behaves like a switch.

## Send a transaction

```ts
const hash = await provider.request({
  method: "eth_sendTransaction",
  params: [{ from: address, to, value: "0x…", data: "0x…" }],
});
```

The wallet opens a review window showing the target, value, calldata hash, chain and the account's security mode, then signs a `MinervaPQTxV1` with the user's ML-DSA-65 key and submits it. You receive the transaction hash and can poll `eth_getTransactionReceipt` as usual. Gas is estimated by the wallet; a `gas` field you pass is treated as a hint.

If the user's account is still counterfactual, the wallet sends the call directly from the undeployed account. No deployment step is needed on your side.

## Sign a message

`personal_sign` and typed-data requests produce an **ML-DSA-65 signature**, not an ECDSA one. `ecrecover`, `verifyMessage` from viem/ethers, and SIWE libraries that recover an address will not verify it. Options:

* On-chain: call the account's EIP-1271 `isValidSignature(hash, signature)` (deployed accounts).
* Off-chain: fetch the account's public key (the wallet returns it with the signature, and the account control registry exposes its commitment) and verify with the ML-DSA-65 verifier in `@minervaquantum/pq-native-tx`.

Treat a Minerva signature as `(address, publicKey, signature)` rather than as 65 bytes.

## Things that look different

| Ethereum habit                       | On Minerva                                                              |
| ------------------------------------ | ----------------------------------------------------------------------- |
| `isContract(addr)` to detect wallets | unreliable; counterfactual accounts have no code and can still transact |
| 21,000 gas for a transfer            | several hundred thousand; use the estimate                              |
| Permit via `ecrecover`               | use EIP-1271-aware variants or approvals                                |
| MetaMask                             | reads work after adding the network; signing needs Minerva Wallet       |

## Test it

The testnet (chain `0x12d52`) has a faucet at `https://testnet.minervachain.org/faucet`; a wallet account has the same address there as on the mainnet, so you can test the full flow without value at risk. Switch the extension's network picker to Minerva Testnet or request the switch from your dapp.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.minervachain.org/build/dapp-integration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
