Programmatic access to the gamma protocol for deposits, withdrawals, and portfolio tracking.
https://app.gma.fi/apiAPI keys use Bearer auth. Contact us to get a key. Keys have read or write scope.
All responses are JSON with success and data or error fields.
All endpoints require an API key. Include it in the Authorization header as a Bearer token.
Authorization: Bearer gma_api_...
| Scope | Access |
|---|---|
read | Read-only endpoints (positions, history, NAV, withdraw status) |
write | All endpoints including deposit and withdraw (write implies read) |
| Status | Meaning |
|---|---|
401 | Missing or invalid API key |
403 | Insufficient scope (e.g. using a read key on a write endpoint) |
429 | Rate limit exceeded |
const API_KEY = 'gma_api_...';
const res = await fetch('https://app.gma.fi/api/positions?wallet=YOUR_WALLET_PUBKEY', {
headers: {
'Authorization': `Bearer ${API_KEY}`,
},
});
const { success, data, error } = await res.json();
if (!success) {
console.error('API error:', error);
} else {
console.log('Positions:', data.vaults);
}/api/positions/api/history/api/vault/{vault_id}/nav/api/vault/{vault_id}/deposit/api/vault/{vault_id}/withdraw/api/vault/{vault_id}/withdrawThe deposit and withdraw endpoints return unsigned transactions that you must sign and submit.
import { Connection, VersionedTransaction } from '@solana/web3.js';
// 1. Fetch the unsigned transaction from our API
const response = await fetch('https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/deposit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
wallet: wallet.publicKey.toBase58(),
amount: 100_000_000 // 100 USDC in lamports (6 decimals)
})
});
const { data } = await response.json();
// 2. Decode the base64 transaction
const txBytes = Buffer.from(data.transaction, 'base64');
const transaction = VersionedTransaction.deserialize(txBytes);
// 3. Sign with your wallet
// Option A: Browser wallet (Phantom, Solflare, etc.)
const signedTx = await window.solana.signTransaction(transaction);
// Option B: Keypair (for programmatic/server use)
// import { Keypair } from '@solana/web3.js';
// const keypair = Keypair.fromSecretKey(...);
// transaction.sign([keypair]);
// 4. Send and confirm
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const signature = await connection.sendRawTransaction(signedTx.serialize());
// 5. Wait for confirmation
const confirmation = await connection.confirmTransaction(signature, 'confirmed');
if (confirmation.value.err) {
throw new Error('Transaction failed');
}
console.log('Transaction confirmed:', signature);
// View on Solscan: https://solscan.io/tx/${signature}// First, check if there's a pending withdrawal to claim
const statusRes = await fetch(
'https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/withdraw?wallet=' + walletPubkey
);
const { data: status } = await statusRes.json();
if (status.hasPendingWithdrawal && status.canClaimNow) {
console.log('Claiming pending withdrawal of', status.estimatedUsdcAmount, 'USDC');
}
// Request the withdrawal transaction (will be claim or initiate based on state)
const withdrawRes = await fetch('https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/withdraw', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
wallet: walletPubkey,
sharesAmount: 50_000_000 // Only needed for new withdrawals
})
});
const { data } = await withdrawRes.json();
console.log('Action:', data.action); // 'initiate' or 'claim'
console.log('Message:', data.message);
// Sign and submit as shown above...