Skip to main content

MoltyDEX SDK - x402 token aggregator for AI agents on Solana. Zero fees, best prices via Jupiter.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moltydex-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moltydex-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file moltydex-1.0.0.tar.gz.

File metadata

  • Download URL: moltydex-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for moltydex-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f403818a1e56a5e4f04a7440f1bc30f67621588d38cf5a8805aa7c598b44f268
MD5 df487086b717885d1942bcdb2dbf5174
BLAKE2b-256 fdd58afa47f41c015319260acaee101c2838bccade496828e388ae4b33d8544f

See more details on using hashes here.

File details

Details for the file moltydex-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: moltydex-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for moltydex-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6b84eccc7180d5acbe3b7b1b5e2eead3bc2897cc37f4d69510a08443a03c389
MD5 d7ace291fc6561d452c7dc048e2df810
BLAKE2b-256 e6881214f24a6076e31f2c80a477dbdc833570a26337437a685549da153bf82a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page