DEV Community

Zaenal Arifin
Zaenal Arifin

Posted on

How to Send Native Crypto Tokens Across Multiple Blockchains Using FastAPI API

Sending native crypto tokens like SOL, ETH, BNB, or BASE programmatically can be challenging, especially when you need to handle transaction signing, network RPC, and error handling.

The Crypto API Service provides a simple solution via its FastAPI endpoints. In this article, we’ll guide you through sending native tokens using the /send/native endpoint with a Python async example.


1️⃣ Prerequisites

  • Python 3.11+
  • Install dependencies:
pip install httpx asyncio
Enter fullscreen mode Exit fullscreen mode
  • RapidAPI key (subscribe to the Crypto API Service)
  • Sender wallet private key (for demo; never expose mainnet keys publicly)
  • Destination wallet address

2️⃣ Understanding the /send/native Endpoint

The endpoint /send/native allows you to send native blockchain tokens:

Required parameters:

  • token: Token symbol (SOL, ETH, BNB, BASE)
  • destination_wallet: Recipient address
  • amount: Amount to send
  • rpc_url: Optional custom RPC URL
  • private_key: Optional private key for signing the transaction

Response:

{
  "status": "success",
  "tx_hash": "5NfL1yS5kJjKx9rR4v8Q7P1M2Zq3vT6Y",
  "message": "SOL successfully sent"
}
Enter fullscreen mode Exit fullscreen mode

3️⃣ Example Python Script

Create send_native.py:

# send_native.py
import asyncio
import httpx
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

API_URL = "https://api.aigoretech.cloud/api/v1/crypto/send/native"
API_KEY = "YOUR_RAPIDAPI_KEY"  # replace with your RapidAPI key

async def send_native_token(token: str, destination_wallet: str, amount: float, rpc_url: str = None, private_key: str = None):
    """Send native token via Crypto API"""
    async with httpx.AsyncClient() as client:
        try:
            if amount <= 0:
                raise ValueError("Amount must be greater than 0")

            logger.info(f"🚀 Sending {amount} {token.upper()} to {destination_wallet}")

            resp = await client.post(
                API_URL,
                params={
                    "token": token,
                    "destination_wallet": destination_wallet,
                    "amount": amount,
                    "rpc_url": rpc_url,
                    "private_key": private_key
                },
                headers={"X-RapidAPI-Key": API_KEY}
            )
            resp.raise_for_status()
            data = resp.json()

            if data.get("status") != "success":
                raise Exception(data.get("message", "Transaction failed"))

            logger.info(f"✅ Transaction successful: {data}")
            return data
        except Exception as e:
            logger.error(f"❌ Failed to send token: {e}", exc_info=True)
            return None

async def main():
    token = "SOL"
    destination_wallet = "YourDestinationWalletAddress"
    amount = 0.01
    rpc_url = "https://api.devnet.solana.com"  # optional, can use default
    private_key = "YOUR_PRIVATE_KEY"           # optional, can be None if using API signing

    result = await send_native_token(token, destination_wallet, amount, rpc_url, private_key)
    if result:
        print(f"Transaction Hash: {result.get('tx_hash')}")
        print(f"Status: {result.get('status')}")
        print(f"Message: {result.get('message')}")

if __name__ == "__main__":
    asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

4️⃣ Example Output

{
  "status": "success",
  "tx_hash": "5NfL1yS5kJjKx9rR4v8Q7P1M2Zq3vT6Y",
  "message": "SOL successfully sent"
}
Enter fullscreen mode Exit fullscreen mode

Console output:

Transaction Hash: 5NfL1yS5kJjKx9rR4v8Q7P1M2Zq3vT6Y
Status: success
Message: SOL successfully sent
Enter fullscreen mode Exit fullscreen mode

5️⃣ How to Run

  1. Save script as send_native.py
  2. Replace YOUR_RAPIDAPI_KEY and YOUR_PRIVATE_KEY (if needed)
  3. Set token, destination wallet, and amount
  4. Run:
python send_native.py
Enter fullscreen mode Exit fullscreen mode
  1. Check console for transaction hash and status

6️⃣ Tips for Safe Token Transfers

  1. Never commit private keys to version control. Use environment variables or secure vaults.
  2. Test on devnet/testnet first before sending mainnet tokens.
  3. Log all responses for debugging and auditing purposes.
  4. Handle exceptions gracefully to avoid lost transactions or crashes.

7️⃣ Closing

Using the /send/native endpoint, you can send SOL, ETH, BNB, or BASE tokens easily without handling low-level blockchain operations. This is ideal for wallet apps, bots, and automated payment systems.

To explore more, you can combine this with balance checking or transaction status monitoring endpoints from the Crypto API Service on RapidAPI.


Suggested Tags for dev.to

python, fastapi, crypto, solana, ethereum, api, tutorial
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
deividas-strole profile image
Deividas Strole

Great article!