# Precompiles

Pod uses precompiles for enshrined applications and internal protocol operations. Precompiles are built into the protocol rather than deployed as user contracts, so they can access internal state (validator signatures, timestamps, merkle proofs) and execute without contract call overhead.

## Precompile Addresses

| Signature                                                                                                | Address                                      | Description                                                           |
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------------- |
| [Orderbook](/guides-references/references/applications-precompiles/orderbook.md)                         | `0x50d0000000000000000000000000000000000002` | Central limit order book for spot and perpetual markets               |
| [Bridge](/guides-references/references/applications-precompiles/bridge.md)                               | `0x50d0000000000000000000000000000000000001` | ERC-20 token bridging between Pod and Ethereum                        |
| [Optimistic Auctions](/guides-references/references/applications-precompiles/wip-optimistic-auctions.md) | `0x50d0000000000000000000000000000000000004` | Censorship-resistant auction for intents (settlement happens off-Pod) |
| [Recovery](/guides-references/references/applications-precompiles/recovery.md)                           | `0x50d0000000000000000000000000000000000003` | Recover a locked account by finalizing the target transaction chain   |

## Interacting with Precompiles

You interact with Pod's precompiles the same way you would interact with any smart contract on Ethereum - by encoding function calls against a Solidity ABI and sending them via `eth_call` (reads) or `eth_sendRawTransaction` (writes).

### Reading State

Query the deposited balance of a token in the orderbook contract using `eth_call`.

{% tabs %}
{% tab title="JavaScript (ethers.js)" %}

```javascript
import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://rpc.podtestnet.dev");

const ORDERBOOK = "0x50d0000000000000000000000000000000000002";
const abi = ["function getBalance(address token) view returns (uint256)"];
const orderbook = new ethers.Contract(ORDERBOOK, abi, provider);

const USDT = "0x0000000000000000000000000000000000000001";
const balance = await orderbook.getBalance(USDT);
console.log("Balance:", balance.toString());
```

{% endtab %}

{% tab title="Python (web3.py)" %}

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://rpc.podtestnet.dev"))

ORDERBOOK = "0x50d0000000000000000000000000000000000002"
abi = [{"inputs": [{"name": "token", "type": "address"}],
        "name": "getBalance",
        "outputs": [{"name": "", "type": "uint256"}],
        "stateMutability": "view", "type": "function"}]

orderbook = w3.eth.contract(address=ORDERBOOK, abi=abi)

USDT = "0x0000000000000000000000000000000000000001"
balance = orderbook.functions.getBalance(USDT).call()
print("Balance:", balance)
```

{% endtab %}

{% tab title="Rust (alloy)" %}

```rust
use alloy::{providers::ProviderBuilder, sol};

sol! {
    #[sol(rpc)]
    contract Orderbook {
        function getBalance(address token) public view returns (uint256);
    }
}

#[tokio::main]
async fn main() -> eyre::Result<()> {
    let provider = ProviderBuilder::new()
        .on_http("https://rpc.podtestnet.dev".parse()?);

    let orderbook = Orderbook::new(
        "0x50d0000000000000000000000000000000000002".parse()?,
        &provider,
    );

    let usdt: Address = "0x0000000000000000000000000000000000000001".parse()?;
    let balance = orderbook.getBalance(usdt).call().await?;
    println!("Balance: {}", balance._0);

    Ok(())
}
```

{% endtab %}
{% endtabs %}

### Submitting Transactions

Send a signed transaction to place a buy order on the orderbook via `eth_sendRawTransaction`.

{% tabs %}
{% tab title="JavaScript (ethers.js)" %}

```javascript
import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://rpc.podtestnet.dev");
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

const ORDERBOOK = "0x50d0000000000000000000000000000000000002";
const abi = [
  `function submitOrder(
    bytes32 orderbookId, int256 size, uint256 price,
    uint8 orderType, uint128 deadline, uint128 ttl,
    bool reduceOnly, bool ioc
  )`
];
const orderbook = new ethers.Contract(ORDERBOOK, abi, signer);

const orderbookId = "0x0000000000000000000000000000000000000000000000000000000000000001"; // NVDAx-USD spot
const size = ethers.parseEther("1");            // buy 1 unit
const price = ethers.parseEther("5000");        // limit price
const orderType = 0;                            // 0 = Limit, 1 = Market
const deadline = BigInt(Date.now()) * 1000n;    // now in microseconds
const ttl = 60n * 1_000_000n;                  // 60 seconds in microseconds

const tx = await orderbook.submitOrder(
  orderbookId, size, price, orderType, deadline, ttl,
  false,    // reduceOnly (perp only)
  false,    // ioc — immediate-or-cancel
);
console.log("Order tx:", tx.hash);
```

{% endtab %}

{% tab title="Python (web3.py)" %}

```python
from web3 import Web3
import time, os

w3 = Web3(Web3.HTTPProvider("https://rpc.podtestnet.dev"))
account = w3.eth.account.from_key(os.environ["PRIVATE_KEY"])

ORDERBOOK = "0x50d0000000000000000000000000000000000002"
abi = [{"inputs": [
    {"name": "orderbookId", "type": "bytes32"},
    {"name": "size", "type": "int256"},
    {"name": "price", "type": "uint256"},
    {"name": "orderType", "type": "uint8"},
    {"name": "deadline", "type": "uint128"},
    {"name": "ttl", "type": "uint128"},
    {"name": "reduceOnly", "type": "bool"},
    {"name": "ioc", "type": "bool"}],
    "name": "submitOrder", "outputs": [],
    "stateMutability": "nonpayable", "type": "function"}]

orderbook = w3.eth.contract(address=ORDERBOOK, abi=abi)

tx = orderbook.functions.submitOrder(
    bytes.fromhex("00" * 31 + "01"),            # orderbook id
    10**18,                                      # size: buy 1 unit
    5000 * 10**18,                               # limit price
    0,                                           # order type: 0 = Limit
    int(time.time() * 1_000_000),                # deadline in microseconds
    60 * 1_000_000,                              # ttl: 60 seconds
    False,                                       # reduce only (perp only)
    False,                                       # ioc (immediate-or-cancel)
).build_transaction({
    "from": account.address,
    "nonce": w3.eth.get_transaction_count(account.address),
})

signed = account.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
print("Order tx:", tx_hash.hex())
```

{% endtab %}

{% tab title="Rust (alloy)" %}

```rust
use alloy::{
    network::EthereumWallet,
    providers::ProviderBuilder,
    signers::local::PrivateKeySigner,
    sol,
    primitives::{U256, I256, FixedBytes},
};

sol! {
    #[sol(rpc)]
    contract Orderbook {
        enum OrderType { Limit, Market }
        function submitOrder(
            bytes32 orderbookId, int256 size, uint256 price,
            OrderType orderType, uint128 deadline, uint128 ttl,
            bool reduceOnly, bool ioc
        ) public;
    }
}

#[tokio::main]
async fn main() -> eyre::Result<()> {
    let signer: PrivateKeySigner = std::env::var("PRIVATE_KEY")?.parse()?;
    let wallet = EthereumWallet::from(signer);

    let provider = ProviderBuilder::new()
        .wallet(wallet)
        .on_http("https://rpc.podtestnet.dev".parse()?);

    let orderbook = Orderbook::new(
        "0x50d0000000000000000000000000000000000002".parse()?,
        &provider,
    );

    let now_us = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)?
        .as_micros() as u128;

    let one_e18 = U256::from(10).pow(U256::from(18));

    let tx = orderbook.submitOrder(
        FixedBytes::left_padding_from(&[1]),     // orderbook id
        I256::from_raw(one_e18),                 // size: buy 1 unit
        U256::from(5000) * one_e18,              // limit price
        Orderbook::OrderType::Limit,             // order type
        now_us,                                   // deadline
        60 * 1_000_000,                          // ttl: 60 seconds
        false,                                    // reduceOnly (perp only)
        false,                                    // ioc — immediate-or-cancel
    ).send().await?;

    println!("Order tx: {:?}", tx.tx_hash());
    Ok(())
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.v2.pod.network/guides-references/references/applications-precompiles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
