Skip to main content

moltydex

Official Python SDK for MoltyDEX — the x402 token aggregator for AI agents on Solana.

  • Zero fees on all swaps
  • Best prices via Jupiter aggregator
  • Automatic x402 payment handling — your agent pays for APIs automatically
  • Token swaps — swap any SPL token with one function call

Install

pip install moltydex

Quick Start

from moltydex import MoltyDEX

dex = MoltyDEX(
    api_url="https://api.moltydex.com",
    wallet_path="~/.config/solana/id.json",
)

# Get a swap quote
quote = dex.quote(
    token_in="So11111111111111111111111111111111111111112",   # SOL
    token_out="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", # USDC
    amount_in=100_000_000,  # 0.1 SOL in lamports
)
print(f"Output: {quote['output_after_fee']} USDC")

Execute a Swap

result = dex.swap(
    token_in="So11111111111111111111111111111111111111112",
    token_out="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    amount_in=100_000_000,
    wait_for_confirmation=True,
)
print(f"Swap signature: {result['signature']}")

Handle x402 Payments

# When your agent gets a 402 Payment Required response:
result = dex.handle_x402_payment(payment_402_response_body)

if result['ready']:
    print("Payment ready — sufficient balance")
else:
    print(f"Swap completed: {result['swap_result']['signature']}")

One-Call Auto-Pay

result = dex.x402_auto_pay(
    payment_response_body=response_402_body,
    auto_swap=True,
)
print(result)

API Reference

Method Description
quote(token_in, token_out, amount_in) Get swap quote
swap(token_in, token_out, amount_in) Execute swap (build, sign, send)
swap_build(token_in, token_out, amount_in) Build unsigned transaction
get_balance(token_mint) Check token balance
parse_x402_payment(body) Parse 402 response
prepare_x402_payment(requirements) Prepare x402 payment
handle_x402_payment(body) Full x402 payment flow
x402_auto_pay(body) One-call auto-pay
search_tokens(query) Search tokens
get_token_by_symbol(symbol) Get token by symbol
get_popular_tokens() List popular tokens
batch_balances(requests) Batch balance checks
batch_quotes(requests) Batch swap quotes
get_transaction_status(signature) Check transaction status
get_transaction_history() Get transaction history

Wallet Configuration

# From file
dex = MoltyDEX(wallet_path="./wallet.json")

# From secret key bytes
dex = MoltyDEX(wallet_secret_key=[1, 2, 3, ...])

# From existing Keypair
from solana.keypair import Keypair
kp = Keypair()
dex = MoltyDEX(wallet_keypair=kp)

Common Token Addresses

Token Mint Address
SOL So11111111111111111111111111111111111111112
USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
USDT Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB

Links

License

MIT

Metadata

Release files for moltydex 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moltydex 1.0.0
File Size Uploaded
moltydex-1.0.0.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moltydex 1.0.0
File Interpreter ABI Platform
moltydex-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / moltydex-1.0.0.tar.gz

Download URL moltydex-1.0.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f403818a1e56a5e4f04a7440f1bc30f67621588d38cf5a8805aa7c598b44f268
BLAKE2b-256 checksum
How to use checksums
fdd58afa47f41c015319260acaee101c2838bccade496828e388ae4b33d8544f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / moltydex-1.0.0-py3-none-any.whl

Download URL moltydex-1.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6b84eccc7180d5acbe3b7b1b5e2eead3bc2897cc37f4d69510a08443a03c389
BLAKE2b-256 checksum
How to use checksums
e6881214f24a6076e31f2c80a477dbdc833570a26337437a685549da153bf82a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page