> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xentfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Development

> Set up your local development environment for testing and integration

This guide covers setting up your development environment for testing and integrating XentFi APIs.

## Test Networks

XentFi provides test networks for all supported blockchains to help you develop and test without using real funds.

### Available Testnets

| Network          | Chain ID | Faucet URL                                               | Native Token |
| ---------------- | -------- | -------------------------------------------------------- | ------------ |
| Sepolia          | 11155111 | [Get ETH](https://sepoliafaucet.com)                     | ETH          |
| Base Sepolia     | 84532    | [Get ETH](https://base.org/faucet)                       | ETH          |
| Mumbai           | 80001    | [Get MATIC](https://faucet.polygon.technology)           | MATIC        |
| Arbitrum Sepolia | 421614   | [Get ETH](https://faucet.quicknode.com/arbitrum/sepolia) | ETH          |
| Optimism Sepolia | 11155420 | [Get ETH](https://app.optimism.io/faucet)                | ETH          |
| BNB Testnet      | 97       | [Get BNB](https://testnet.bnbchain.org/faucet-smart)     | BNB          |
| Solana Devnet    | 1        | [Get SOL](https://faucet.solana.com)                     | SOL          |

## Development vs Production Comparison

| Aspect               | Development                     | Production           |
| -------------------- | ------------------------------- | -------------------- |
| **Network**          | Testnet (Sepolia, Mumbai, etc.) | Mainnet              |
| **API Keys**         | Sandbox keys                    | Production keys      |
| **Funds**            | Faucet tokens (free)            | Real cryptocurrency  |
| **Transaction Cost** | Free (testnet gas)              | Real gas fees        |
| **Rate Limits**      | Higher limits                   | Standard limits      |
| **Monitoring**       | Optional                        | Required             |
| **Webhooks**         | Use ngrok for local testing     | Production endpoints |

## Environment Setup

### 1. Get Sandbox API Keys

<Steps>
  <Step title="Log into Dashboard">
    Go to [dashboard.xentfi.com](https://dashboard.xentfi.com)
  </Step>

  <Step title="Create Sandbox Keys">
    Navigate to **Settings → API Keys** and select "Sandbox" environment
  </Step>

  <Step title="Save Credentials">
    Copy your sandbox `apiKey` and `orgId`
  </Step>
</Steps>

### 2. Configure Environment Variables

Create a `.env` file in your project:

```
# XentFi Sandbox Configuration
XENTFI_API_KEY=your_sandbox_api_key
XENTFI_ORG_ID=your_org_id
XENTFI_BASE_URL=https://api.xentfi.com/v1
XENTFI_ENVIRONMENT=sandbox

# Webhook Testing (optional)
XENTFI_WEBHOOK_SECRET=your_webhook_secret
XENTFI_WEBHOOK_URL=https://your-ngrok-url/webhooks/xentfi

# Network Configuration (optional)
XENTFI_DEFAULT_NETWORK=sepolia
```

### 3. Install SDK

<CodeGroup>
  ```
  # Node.js / TypeScript
  npm install @xentfi/sdk
  ```

  ```
  # Python
  pip install xentfi
  ```

  ```
  # Go
  go get github.com/xentfi/xentfi-go
  ```
</CodeGroup>

### 4. Initialize Client

<CodeGroup>
  ```
  // Node.js
  import { XentFiClient } from '@xentfi/sdk';

  const client = new XentFiClient({
  apiKey: process.env.XENTFI_API_KEY,
  orgId: process.env.XENTFI_ORG_ID,
  environment: 'sandbox',
  network: 'sepolia' // default testnet
  });
  ```

  ```
  # Python
  from xentfi import XentFiClient

  client = XentFiClient(
  api_key=os.environ['XENTFI_API_KEY'],
  org_id=os.environ['XENTFI_ORG_ID'],
  environment='sandbox',
  network='sepolia'
  )
  ```
</CodeGroup>

## Local Development with Testnet

### Getting Test Tokens

<Steps>
  <Step title="Create a Test Wallet">
    First, create a master wallet on your chosen testnet:

    ```
    curl -X POST https://api.xentfi.com/v1/master-wallets \
    -H "apiKey: $XENTFI_API_KEY" \
    -H "orgId: $XENTFI_ORG_ID" \
    -d '{
    "name": "Test Wallet",
    "blockchainId": "eth-sepolia"
    }'
    ```
  </Step>

  <Step title="Get Wallet Address">
    Copy the `walletAddress` from the response.
  </Step>

  <Step title="Request Test Tokens">
    Visit the faucet for your chosen testnet and paste your wallet address.
  </Step>

  <Step title="Verify Balance">
    ```
    curl -X GET https://api.xentfi.com/v1/addresses/{addressId}/balance \
    -H "apiKey: $XENTFI_API_KEY" \
    -H "orgId: $XENTFI_ORG_ID"
    ```
  </Step>
</Steps>

## Webhook Testing with ngrok

For local webhook development, use ngrok to expose your local server:

```
# Install ngrok (macOS)
brew install ngrok

# Or download from https://ngrok.com/download

# Start ngrok on port 3000
ngrok http 3000

# Copy the HTTPS URL (e.g., https://abc123.ngrok.io)
```

Configure your webhook with the ngrok URL:

```
curl -X POST https://api.xentfi.com/v1/webhooks \
-H "apiKey: $XENTFI_API_KEY" \
-H "orgId: $XENTFI_ORG_ID" \
-d '{
"url": "https://abc123.ngrok.io/webhooks/xentfi",
"events": ["payment.completed", "payment.failed"],
"secret": "your-webhook-secret"
}'
```

## Sample Development Workflow

```
flowchart LR
subgraph Local["Local Development"]
Code[Write Code]
Test[Run Tests]
Debug[Debug Issues]
end

subgraph Testnet["Testnet Environment"]
Wallet[Create Test Wallet]
Payment[Process Test Payment]
Webhook[Receive Webhook]
end

subgraph Production["Production"]
Deploy[Deploy to Production]
Monitor[Monitor Transactions]
end

Local --> Testnet
Testnet --> Production
```

## Testing Checklist

Before moving to production, ensure you've tested:

* [ ] API key authentication works
* [ ] Master wallet creation succeeds
* [ ] Deposit address generation works
* [ ] Payment link creation and access
* [ ] Payment processing with test tokens
* [ ] Webhook events received and verified
* [ ] Signature verification implemented
* [ ] Error handling for all scenarios
* [ ] Rate limit handling
* [ ] Idempotency keys working correctly
* [ ] Balance checking functionality

## Common Development Issues

<AccordionGroup>
  <Accordion title="Insufficient testnet funds">
    **Solution:** Request more tokens from the faucet. Some faucets have daily limits.
  </Accordion>

  <Accordion title="Webhook not received">
    **Solution:**

    * Verify ngrok is running
    * Check webhook URL is accessible
    * Verify signature verification
  </Accordion>

  <Accordion title="Transaction not confirming">
    **Solution:**

    * Testnet may be congested
    * Increase gas limit
    * Wait and retry
  </Accordion>

  <Accordion title="Rate limit hit during testing">
    **Solution:**

    * Sandbox has higher limits
    * Implement delays between requests
    * Contact support for temporary increase
  </Accordion>
</AccordionGroup>

## Migrating to Production

<Steps>
  <Step title="Generate Production Keys">
    Create new API keys with "Production" environment in dashboard
  </Step>

  <Step title="Update Configuration">
    Change environment from sandbox to production
  </Step>

  <Step title="Deploy Webhooks">
    Update webhook URLs to production endpoints
  </Step>

  <Step title="Create Production Wallets">
    Deploy wallets on mainnet networks
  </Step>

  <Step title="Enable Monitoring">
    Turn on monitoring for all production wallets
  </Step>

  <Step title="Go Live">
    Update your application configuration and launch
  </Step>
</Steps>

## Pre-Migration Checklist

* [ ] All tests pass on testnet
* [ ] Error handling implemented
* [ ] Rate limit handling in place
* [ ] Webhook signature verification working
* [ ] Idempotency keys implemented
* [ ] Monitoring and alerting configured
* [ ] Security review completed
* [ ] Backup and recovery procedures ready

## Support During Development

* 📧 **Developer Support**: [dev@xentfi.com](mailto:dev@xentfi.com)
* 💬 **Discord**: [#dev channel](https://discord.gg/xentfi)
* 📚 **API Reference**: [docs.xentfi.com/api-reference](https://docs.xentfi.com/api-reference)
* 🐛 **Report Issues**: [GitHub Issues](https://github.com/xentfi/api/issues)

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/authentication">
    Learn about API security best practices
  </Card>

  <Card title="Rate Limits" icon="speedometer" href="/rate-limits">
    Understand API rate limiting
  </Card>

  <Card title="Products" icon="package" href="/essentials/master-wallets">
    Explore all XentFi products
  </Card>

  <Card title="API Reference" icon="book-open" href="/api-reference">
    Browse complete API documentation
  </Card>
</CardGroup>
