Skip to main content

Setup your development environment

Follow these steps to integrate Darex into your application.

Option 1: Direct Smart Contract Integration

Perfect for DeFi protocols and wallets that want to interact directly with our contracts.
1

Install Dependencies

Install the necessary packages:
npm install viem wagmi
# or
yarn add viem wagmi
2

Configure Contract Addresses

Import the deployed contract addresses (Base Mainnet):
const DAREX_ROUTER = "0x0a5f1906f77b39A9eDFB4d3AA7542C31A257dbd7";
const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
3

Make Your First Deposit

Execute a deposit to Aave USDC using the Darex Router:
import { parseUnits } from 'viem';

// Instrument ID for Aave USDC on Base
const AAVE_USDC_ID = "0x00002105c053a3e1290845e12a3eea14926472ce7f15da324cdf0700056fc04b";
const amount = parseUnits("1000", 6); // 1000 USDC

// 1. Approve Darex Router to spend your USDC
await usdc.write.approve([DAREX_ROUTER, amount]);

// 2. Execute deposit via Darex Router
// This abstracts all Uniswap V4 and Permit2 complexity
await darexRouter.write.deposit([
  AAVE_USDC_ID, 
  amount, 
  0n // minSwapOutput (0 for no slippage check)
]);

Option 2: REST API Integration

Perfect for applications that need instrument discovery and metrics.
1

Get Your API Key

Sign up at https://app.darex.com/api-keys to get your API key.
2

Make Your First Request

Fetch all available instruments:
curl -H "X-API-Key: your-api-key" \
  https://api.darex.com/api/v1/instruments
3

Query Specific Instrument

Get details for a specific instrument:
curl -H "X-API-Key: your-api-key" \
  https://api.darex.com/api/v1/instruments/0x00002105c053a3e1290845e12a3eea14926472ce7f15da324cdf0700056fc04b

Option 3: Embedded Wallet Integration

Perfect for AI agents and robo-advisors that need automated trading.
1

Install Privy SDK

npm install @privy-io/react-auth wagmi viem
2

Configure Privy Provider

import { PrivyProvider } from '@privy-io/react-auth';

<PrivyProvider
  appId="your-privy-app-id"
  config={{
    embeddedWallets: {
      createOnLogin: 'all-users',
    },
  }}
>
  <YourApp />
</PrivyProvider>
3

Create Session Keys

Enable automated trading within limits:
import { usePrivy } from '@privy-io/react-auth';

const { createSessionKey } = usePrivy();

// Create session key with limits
await createSessionKey({
  maxAmount: parseEther("10000"), // Max 10k USDC
  expiry: Date.now() + 86400000, // 24 hours
});

Example Use Cases

Next Steps