Skip to main content

intents.py

PyPI Python Docs License

An async Python wrapper for the NEAR Intents 1Click Swap API.

pip install intents-py

Requirements

  • Python 3.10+
  • httpx
  • pydantic

Quickstart

import asyncio
from intents import IntentsClient, find_token

async def main():
    async with IntentsClient() as client:
        tokens = await client.get_tokens()
        eth = find_token(tokens, "eth", "ETH")
        print(eth.asset_id)  # nep141:eth.omft.near

asyncio.run(main())

Swap flow

import asyncio
from datetime import datetime, timedelta, timezone
from intents import (
    IntentsClient,
    QuoteRequest,
    SwapType,
    DepositType,
    RecipientType,
    RefundType,
    SwapStatus,
    find_token,
    token_to_atomic,
)

async def main():
    async with IntentsClient(jwt_token="your-jwt-token") as client:
        tokens = await client.get_tokens()
        eth  = find_token(tokens, "eth", "ETH")
        usdc = find_token(tokens, "arb", "USDC")

        # 1. Get a quote
        response = await client.get_quote(QuoteRequest(
            dry=False,
            swap_type=SwapType.EXACT_INPUT,
            slippage_tolerance=100,          # 1% — use pct_to_bps(1) for clarity
            origin_asset=eth.asset_id,
            destination_asset=usdc.asset_id,
            deposit_type=DepositType.ORIGIN_CHAIN,
            amount=token_to_atomic("0.01", eth),
            refund_to="0xYourAddress",
            refund_type=RefundType.ORIGIN_CHAIN,
            recipient="0xYourAddress",
            recipient_type=RecipientType.DESTINATION_CHAIN,
            deadline=datetime.now(timezone.utc) + timedelta(hours=1),
        ))

        quote = response.quote
        print(f"Send {quote.amount_in_formatted} ETH to {quote.deposit_address}")
        if quote.deposit_memo:
            print(f"Memo (required): {quote.deposit_memo}")

        # 2. Send funds to quote.deposit_address, then poll for status
        while True:
            status = await client.get_status(quote.deposit_address, quote.deposit_memo)
            print(status.status)
            if status.status in {SwapStatus.SUCCESS, SwapStatus.REFUNDED, SwapStatus.FAILED}:
                break
            await asyncio.sleep(10)

asyncio.run(main())

Authentication

Most endpoints require a JWT token. Pass it when constructing the client:

client = IntentsClient(jwt_token="your-jwt-token")

API reference

Full API reference is on Read the Docs.

IntentsClient

Method Description
get_tokens() List all supported tokens
get_quote(request) Request a swap quote
get_status(deposit_address, deposit_memo?) Check swap status
get_any_input_withdrawals(deposit_address, ...) Get withdrawals for an ANY_INPUT quote
submit_deposit(request) Notify the service a deposit has been sent

Utilities

Function Description
find_token(tokens, blockchain, symbol) Look up a token by chain and symbol
to_atomic(amount, decimals) Convert 0.1 → "100000000000000000"
from_atomic(amount, decimals) Convert "100000000000000000" → Decimal("0.1")
token_to_atomic(amount, token) to_atomic using a TokenResponse
token_from_atomic(amount, token) from_atomic using a TokenResponse
pct_to_bps(percent) Convert 1 (%) → 100 (bps)
bps_to_pct(bps) Convert 100 (bps) → Decimal("1") (%)

Swap types

Value Behaviour
EXACT_INPUT Specify input amount, receive calculated output
EXACT_OUTPUT Specify output amount, deposit calculated input
FLEX_INPUT Variable input with slippage bounds
ANY_INPUT Multiple partial deposits over time

Swap statuses

KNOWN_DEPOSIT_TX → PENDING_DEPOSIT → PROCESSING → SUCCESS

Terminal states: SUCCESS, REFUNDED, FAILED

Examples

See the examples/ directory:

License

MIT

Metadata

Release files for intents-py 0.1.1

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

Source distribution (sdist)

Source distribution for intents-py 0.1.1
File Size Uploaded Provenance Actions
intents_py-0.1.1.tar.gz 22.3 kB Without provenance Details for intents_py-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for intents-py 0.1.1
File Interpreter ABI Platform Actions
intents_py-0.1.1-py3-none-any.whl Python 3 none any Details for intents_py-0.1.1-py3-none-any.whl

Total release size: 32.5 kB

Release files / intents_py-0.1.1.tar.gz

Download URL intents_py-0.1.1.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ccaa1a687cd7e21932428340d6aa2a1c935bca096eb014d7ffb176a9bf219da5
BLAKE2b-256 checksum
How to use checksums
ac7fede7007e5db9436e0e1adeec88e49b2937f4dbbed56cafe0d7022bd11194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / intents_py-0.1.1-py3-none-any.whl

Download URL intents_py-0.1.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7df01245af8c1a46d6ab2d6d62e118443ef614a59078bada3d2f8ba5bea35a57
BLAKE2b-256 checksum
How to use checksums
bf70ba6c9d37c657aff6356fa0cd41b71b15e72138c30d0dd7c621d507b1b663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for intents-py 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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