> For the complete documentation index, see [llms.txt](https://docs.seismic.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seismic.systems/clients/python/precompiles.md).

# Precompiles

Call Mercury EVM precompiles from Python

The Python SDK exposes wrappers for six Mercury EVM precompiles (`0x64` through `0x69`).

These wrappers use plain `eth_call`, so you only need a `Web3` connection to a Seismic node. No wallet client or encryption state is required.

## Quick Start

```python
import os
from seismic_web3 import PrivateKey, create_public_client
from seismic_web3.crypto.secp import private_key_to_compressed_public_key
from seismic_web3 import precompiles as sp

w3 = create_public_client("https://testnet-1.seismictest.net/rpc")

# 1) Random bytes as int
random_val = sp.rng(w3, num_bytes=32)

# 2) Shared key from ECDH
my_sk = PrivateKey(os.urandom(32))
peer_sk = PrivateKey(os.urandom(32))
peer_pk = private_key_to_compressed_public_key(peer_sk)
shared_key = sp.ecdh(w3, sk=my_sk, pk=peer_pk)

# 3) AES-GCM encrypt/decrypt
ciphertext = sp.aes_gcm_encrypt(
    w3,
    aes_key=shared_key,
    nonce=1,
    plaintext=b"secret",
)
plaintext = sp.aes_gcm_decrypt(
    w3,
    aes_key=shared_key,
    nonce=1,
    ciphertext=bytes(ciphertext),
)

# 4) HKDF derivation
derived_key = sp.hkdf(w3, b"input key material")

# 5) secp256k1 signing
signature = sp.secp256k1_sign(w3, sk=my_sk, message="hello")
```

All wrappers also have async variants: `async_rng`, `async_ecdh`, `async_aes_gcm_encrypt`, `async_aes_gcm_decrypt`, `async_hkdf`, `async_secp256k1_sign`.

## Reference

| Precompile     | Address | Function                                                                                               | Returns    |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------ | ---------- |
| RNG            | `0x64`  | [`rng(w3, num_bytes=, pers=)`](/clients/python/precompiles/rng.md)                                     | `int`      |
| ECDH           | `0x65`  | [`ecdh(w3, sk=, pk=)`](/clients/python/precompiles/ecdh.md)                                            | `Bytes32`  |
| AES Encrypt    | `0x66`  | [`aes_gcm_encrypt(w3, aes_key=, nonce=, plaintext=)`](/clients/python/precompiles/aes-gcm-encrypt.md)  | `HexBytes` |
| AES Decrypt    | `0x67`  | [`aes_gcm_decrypt(w3, aes_key=, nonce=, ciphertext=)`](/clients/python/precompiles/aes-gcm-decrypt.md) | `HexBytes` |
| HKDF           | `0x68`  | [`hkdf(w3, ikm)`](/clients/python/precompiles/hkdf.md)                                                 | `Bytes32`  |
| secp256k1 Sign | `0x69`  | [`secp256k1_sign(w3, sk=, message=)`](/clients/python/precompiles/secp256k1-sign.md)                   | `HexBytes` |


---

# 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.seismic.systems/clients/python/precompiles.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.
