import {
CapaV2Client,
CreatePartnerOffRampTransactionV2RequestBody,
CreatePartnerUserBody,
blockchainSymbol,
fiatCurrency,
tokenSymbol,
transactionType,
userType
} from '@capa-fi/sdk';
async function main() {
// Initialize client
const client = new CapaV2Client(
{
baseUrl: "https://production-api.capa.fi",
partnerApiKey: "your-partner-api-key"
},
);
try {
// 1. Create a user
const userRes = await client.users.createUser({
type: userType.INDIVIDUAL,
email: "user@example.com",
externalUserId: "unique-external-id"
});
const userId = userRes.data?.userId;
if (!userId) {
throw new Error("Failed to create user");
}
// 2. Get a quote
const quoteRes = await client.quotes.getPartnerQuoteRate(
tokenSymbol.USDC,
"ON_RAMP",
blockchainSymbol.ETH,
fiatCurrency.MXN,
undefined,
1000 // 1000 MXN
);
console.log("Quote:", quoteRes.data);
// 3. Create an on-ramp transaction
const onRampRes = await client.onRamp.createPartnerOnRamp({
userId,
fiatCurrency: fiatCurrency.MXN,
blockchainSymbol: blockchainSymbol.ETH,
tokenSymbol: tokenSymbol.USDC,
fiatAmount: 1000,
destinationWalletAddress: "your-wallet-address"
});
console.log("On-ramp transaction:", onRampRes.data?.id);
// 4. Create an off-ramp transaction
const offRampRes = await client.offRamp.createPartnerOffRamp({
userId,
fiatCurrency: fiatCurrency.MXN,
blockchainSymbol: blockchainSymbol.ETH,
tokenSymbol: tokenSymbol.USDC,
fiatAmount: 500,
userBankInformation: {
country: "MX",
accountIdentifier: "012345678901234567"
}
});
console.log("Off-ramp transaction:", offRampRes.data?.id);
// 5. List user transactions
const transactionsRes = await client.transactions.listPartnerUserTransactions({
type: transactionType.ON_RAMP,
fiatCurrency: fiatCurrency.MXN,
userId: userId,
skip: 1,
limit: 20
});
console.log(`Found ${transactionsRes.data?.data?.length} transactions`);
} catch (error) {
console.error("Error:", error);
}
}
main();