Skip to main content

Buy and Sell

Buy and sell operations convert between fiat and crypto. A buy (on-ramp) converts fiat currency into stablecoins and deposits them into a customer's wallet. A sell (off-ramp) converts stablecoins back into fiat and sends the funds to a customer's bank account or PIX key. These flows are powered by Bridge (on-ramp) and Avenia (off-ramp).

import { createOakClient, createBuyService, createSellService } from '@oaknetwork/api';

const client = createOakClient({ ... });

const buy = createBuyService(client); // on-ramp: fiat → crypto
const sell = createSellService(client); // off-ramp: crypto → fiat

Buy (on-ramp)

Convert fiat to crypto via Bridge.

Methods

MethodDescription
create(request)Create a buy transaction

Create a buy

const result = await buy.create({
provider: 'bridge',
source: {
currency: 'usd',
amount: 10000,
},
destination: {
currency: 'usdc',
customer: { id: 'cus_abc123' },
payment_method: {
type: 'customer_wallet',
chain: 'polygon',
evm_address: '0x1234567890abcdef1234567890abcdef12345678',
},
},
});

if (result.ok) {
console.log('Buy ID:', result.value.data.id);
console.log('Status:', result.value.data.status);
}

Buy request fields

FieldTypeDescription
provider"bridge"Currently only Bridge is supported
source.currency"usd"Source fiat currency
source.amountnumberAmount in smallest unit (optional)
destination.currency"usdc" | "usdt" | "usdb"Target stablecoin
destination.customer.idstringCustomer UUID
destination.payment_method.type"customer_wallet"Must be a crypto wallet
destination.payment_method.chainstringTarget chain (ethereum, polygon, arbitrum, solana)
destination.payment_method.evm_addressstringDestination wallet address

Buy response

FieldTypeDescription
idstringTransaction ID
statusstringStatus (e.g., "captured")
type"buy"Always "buy"
provider"bridge" | "brla"Provider used
sourceobjectSource currency and amount
destinationobjectDestination currency, customer, and wallet
provider_responseobjectRaw provider response
created_atstringISO timestamp
updated_atstringISO timestamp

Sell (off-ramp)

Convert crypto to fiat via Avenia.

Methods

MethodDescription
create(request)Create a sell transaction

Create a sell

const result = await sell.create({
provider: 'avenia',
source: {
customer: { id: 'cus_abc123' },
currency: 'brla',
amount: 5000,
},
destination: {
customer: { id: 'cus_def456' },
currency: 'brl',
payment_method: {
type: 'pix',
id: 'pm_pix_xyz',
},
},
});

if (result.ok) {
console.log('Sell ID:', result.value.data.id);
console.log('Status:', result.value.data.status);
}

Sell request fields

FieldTypeDescription
provider"avenia"Currently only Avenia is supported
source.customer.idstringSource customer UUID (optional — defaults to master account)
source.currencystringSource currency (e.g., "brla")
source.amountnumberAmount to sell
destination.customer.idstringDestination customer UUID
destination.currencystringTarget fiat currency (e.g., "brl")
destination.payment_methodobjectPIX payment method — either { type: "pix", id } or { type: "pix", pix_string }

Sell response

FieldTypeDescription
idstringTransaction ID
statusstringStatus (e.g., "created")
type"sell"Always "sell"
providerstringProvider used
sourceobjectSource amount and currency
destinationobjectDestination currency, customer, and payment method
created_atstringISO timestamp
updated_atstringISO timestamp