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:
const SWAP_DEPOSITOR = "0x77F1D92816eAfc6f0077e0840b1794D3De074A88";
const INSTRUMENT_REGISTRY = "0x0b12B474Fb4087CbCB3C886bbCeC29ff7AE13428";
3

Make Your First Deposit

Execute a deposit to Aave USDC:
import { encodePacked } from 'viem';

// Instrument ID for Aave USDC on Base
const AAVE_USDC_ID = "0x00007a69c053a3e1290845e12a3eea14926472ce7f15da324cdf0700056fc04b";

// Encode hook data
const hookData = encodePacked(
  ['bytes32', 'uint8'],
  [AAVE_USDC_ID, 0] // 0 = deposit
);

// Execute swap (which triggers deposit)
await swapRouter.write.swap({
  poolKey: HOOK_POOL_KEY,
  zeroForOne: true,
  amountSpecified: parseUnits("1000", 6), // 1000 USDC
  hookData,
});

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/0x00007a69c053a3e1290845e12a3eea14926472ce7f15da324cdf0700056fc04b

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