A TypeScript example project demonstrating how to interact with the Deriverse decentralized trading protocol on Solana. This example shows how to connect to the Deriverse exchange, manage client accounts, deposit funds, and execute spot trading operations.
This project uses the @deriverse/kit library to:
- Initialize and connect to the Deriverse trading engine
- Set up client accounts for trading
- Deposit USDC tokens for trading
- Place and cancel spot orders for SOL/USDC trading pairs
- Interact with Solana's devnet environment
- Node.js (v20 or higher)
- TypeScript
- A Solana wallet keypair file
- Access to Solana devnet
- Clone this repository:
git clone https://github.com/deriverse/kit-example.git
cd kit-example- Install dependencies:
npm install- Set up environment variables by copying
.env.exampleto.env:
cp .env.example .envCreate a .env file with the following variables:
KEYPAIR_FILENAME=../keys/new_user.json
PROGRAM_ID=Drvrseg8AQLP8B96DBGmHRjFGviFNYTkHueY9g3k27Gu
RPC_HTTP=https://api.devnet.solana.com
RPC_WS=wss://api.devnet.solana.com
VERSION=12
TOKEN_MINT_A=9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP #Wrapped SOL (Token 2022)
TOKEN_MINT_B=A2Pz6rVyXuadFkKnhMXd1w9xgSrZd8m8sEGpuGuyFhaj #Fake Deriverse Devnet USDC (SPL Token)- KEYPAIR_FILENAME: Path to your Solana wallet keypair JSON file
- PROGRAM_ID: Deriverse program ID on Solana
- RPC_HTTP: Solana RPC HTTP endpoint (devnet)
- RPC_WS: Solana RPC WebSocket endpoint (devnet)
- VERSION: Deriverse Protocol Data Structure version
- TOKEN_MINT_A: Wrapped SOL token mint address (Asset token)
- TOKEN_MINT_B: USDC token mint address (Currency token)
- Generate a new Solana keypair or use an existing one:
solana-keygen new --outfile keys/new_user.json- Fund your wallet with devnet SOL:
solana airdrop 2 <your-wallet-address> --url devnet- Make sure you have some devnet USDC tokens for trading.
- Build the TypeScript project:
npm run build- Run the example:
node build/index.jsThe example script performs the following operations:
- Initialize Engine: Connects to the Deriverse trading protocol
- Client Setup: Creates or loads an existing client account
- Token Validation: Validates the trading pair (SOL/USDC)
- Fund Deposit: Deposits 100 USDC if the account balance is insufficient
- Order Management:
- Cancels existing bid orders (if any)
- Places a new bid order at 99% of market price
- Asset Token: Wrapped SOL (TOKEN_MINT_A)
- Currency Token: USDC (TOKEN_MINT_B)
- Order Type: Limit orders
- Strategy: Places bid orders 1% below market price
- Quantity: Calculates quantity based on $100 worth of the asset
├── src/
│ └── index.ts # Main application logic
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── .env.example # Environment variables template
- @deriverse/kit: Core library for Deriverse protocol interaction
- @solana/kit: Solana Web3.js v2 toolkit
- dotenv: Environment variable management
- TypeScript: Static typing for JavaScript
This example is configured for Solana Devnet:
- RPC:
https://api.devnet.solana.com - WebSocket:
wss://api.devnet.solana.com
- Invalid Token Mint: Ensure TOKEN_MINT_A and TOKEN_MINT_B are valid devnet addresses
- Insufficient Funds: Make sure your wallet has enough SOL for transaction fees
- Keypair Loading Error: Check the KEYPAIR_FILENAME path and file format
- Check console output for Client ID and transaction signatures
- Monitor your wallet and Deriverse Account balances before and after running the script
- Verify environment variables are correctly set