> 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/smart-contracts.md). Agents can also search and read this documentation through its [MCP server](https://docs.minervachain.org/~gitbook/mcp).

# Smart contracts on Minerva

Minerva runs the Ethereum Virtual Machine with every EIP up to and including EIP-1559, EIP-3529 and EIP-3541 active from genesis. Solidity, Foundry, Hardhat and viem work as on any EVM chain. The differences are all about **who calls you**.

## What is the same

* Opcodes, precompiles `0x01` to `0x09`, gas schedule (Berlin/London era), `CREATE2`, EIP-1559 base fee.
* Contract addresses derive from sender and nonce (or `CREATE2`) exactly as on Ethereum.
* Logs, receipts, `eth_call`, `eth_estimateGas`, `eth_getLogs` behave as usual.
* Verified sources: the indexer accepts standard JSON input at `POST /api/indexer/contracts/:address/verify`, and Blockscout at `blockscout-mainnet.minervachain.org` indexes independently.

## What is different

**`msg.sender` is always a smart account.** There are no EOAs. `tx.origin` equals `msg.sender` for a direct call, and both are the Minerva account address, whether or not that account's contract is deployed yet.

**Do not use `extcodesize == 0` to mean "is a wallet".** A counterfactual Minerva account has no code and can still call you. Likewise, do not assume an address with code is a contract you can reason about: a deployed Minerva account is both a wallet and a contract.

**`ecrecover` does not verify Minerva users.** A Minerva account signs with ML-DSA-65. To verify a signature from a user, either call the account's EIP-1271 `isValidSignature(hash, signature)` (deployed accounts), or verify the ML-DSA-65 signature yourself through the precompile at `0x…4D00`:

```solidity
address constant MLDSA65 = 0x0000000000000000000000000000000000004D00;

function verifyMLDSA(bytes memory publicKey, bytes memory message, bytes memory context, bytes memory signature)
    internal view returns (bool)
{
    (bool ok, bytes memory out) = MLDSA65.staticcall(abi.encode(publicKey, message, context, signature));
    return ok && abi.decode(out, (bool));
}
```

Permit-style flows (`EIP-2612`) that rely on `ecrecover` therefore do not work for Minerva accounts. Use EIP-1271-aware permit variants or on-chain approvals.

**Know who is executing.** Inside a native transaction, the precompile `0x…4D01` returns the signer's account, key commitment, algorithm, policy version and factory salt. It returns zeros for internal calls that did not originate from a native transaction. This lets a contract distinguish the control key from a device key if it needs to.

**No legacy transaction types.** Scripts that broadcast type `0x00`, `0x01` or `0x02` transactions are rejected. Deployment scripts must sign a `MinervaPQTxV1`; see [Send a PQ transaction](https://docs.minervachain.org/build/send-pq-transaction.md). Foundry's `forge script --broadcast` cannot sign Minerva transactions today; use `forge build` and deploy the creation bytecode with the SDK.

## Deploying

```ts
import { createMinervaClient, sendPQTransaction } from "@minervaquantum/sdk";

const client = createMinervaClient({ networkName: "mainnet" });
const bytecode = "0x6080…";   // forge build output, constructor args appended

const hash = await sendPQTransaction(client, {
  nonce: await client.getTransactionCount({ address: account.address }),
  gasTipCap: 1_000_000_000n,
  gasFeeCap: 2_000_000_000n,
  gas: 3_000_000n,
  to: undefined,
  value: 0n,
  data: bytecode,
  pqPublicKey: account.publicKey,
  pqPrivateKey: account.privateKey,
});
const receipt = await client.waitForTransactionReceipt({ hash });
console.log(receipt.contractAddress);
```

Then verify the source through the indexer or Blockscout so the explorer can decode calls to it.

## System addresses you may call

| Address   | Use from a contract                                           |
| --------- | ------------------------------------------------------------- |
| `0x…4D00` | verify ML-DSA-65 signatures                                   |
| `0x…4D01` | read the native transaction context                           |
| `0x…0203` | predict or deploy Minerva account addresses (`createAccount`) |
| `0x…0204` | read an account's current key commitment and policy version   |
| `0x…0303` | the bridge vault, if you build on top of bridge events        |

Full table in [Precompiles and system contracts](https://docs.minervachain.org/protocol/system-contracts.md).


---

# 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/smart-contracts.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.
