Skip to main content
POST
/
trade-token
Trade tokens (buy or sell)
curl --request POST \
  --url https://yppncslmsswqydhhgygz.supabase.co/functions/v1/trade-token \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "tokenId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "chainSlug": "base-sepolia",
  "direction": "buy",
  "userAddress": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "builder": {
    "code": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
    "fee": 50
  },
  "token_referral": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "buyAmountUSD": 1,
  "buyAmountToken": 1000,
  "sellAmountToken": 1000,
  "sellAmountUSD": 1
}
'
{
  "success": true,
  "transaction": {
    "to": "<string>",
    "data": "<string>",
    "value": "<string>",
    "gasLimit": "<string>",
    "chain": "base-sepolia"
  }
}

Authorizations

Authorization
string
header
required

JWT token or API key

Body

application/json
tokenId
string<uuid>
required
chainSlug
enum<string>
required

Blockchain identifier. Supported chains: solana, solana-devnet, arbitrum, base, base-sepolia, avalanche, op-bnb, bnb, bnb-testnet, ethereum, monad, unichain, unichain-testnet, abstract, polygon, zksync, zksync-testnet

Available options:
solana,
solana-devnet,
arbitrum,
base,
base-sepolia,
avalanche,
op-bnb,
bnb,
bnb-testnet,
ethereum,
monad,
unichain,
unichain-testnet,
abstract,
polygon,
zksync,
zksync-testnet
Example:

"base-sepolia"

direction
enum<string>
required
Available options:
buy,
sell
userAddress
string

User wallet address (optional - if not provided, will use user's Privy wallet from user_wallets table)

Example:

"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"

builder
object

Builder attribution information (optional). Includes address and fee in bps.

token_referral
string

Token referral address for attribution (optional - defaults to zero address). Used to attribute referral fees to a specific address.

Example:

"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"

buyAmountUSD
number
Required range: x > 0
buyAmountToken

Token amount to buy (number for regular amounts, string for exact wei values at 100%)

Required range: x > 0
Example:

1000

sellAmountToken

Token amount to sell (number for regular amounts, string for exact wei values at 100%)

Required range: x > 0
Example:

1000

sellAmountUSD
number
Required range: x > 0

Response

Successful response

success
enum<boolean>
required
Available options:
true,
false
transaction
object
required