Referral Smart Contract (1.0.0)
Download OpenAPI specification:Download
The Referral Smart Contract enables dApp integrators to earn referral fees on swaps routed through their application. It executes a normal router swap and then splits the final output between the referral address and the user.
The Referral contract provides:
- On-chain Referral Fees: Your dApp earns fees directly on-chain for swaps it routes
- Automatic Output Splitting: After swap, output is split between referral and user
- Configurable Percentage: Referral percentage from 0.1% to 5% (base 100,000)
After the swap output is determined:
referral_amount = amount_out_total * referral_percentage / 100000destination_amount = amount_out_total - referral_amount
- Referral amount → sent to your
referral_address - User amount → sent to
amount_out_destination(or caller if not provided)
referral_percentage uses a base of 100_000:
| Value | Percentage |
|---|---|
100 |
0.1% |
1_000 |
1.0% |
5_000 |
5.0% (max) |
Before sending the swap transaction, request a quotation using token asset IDs:
Endpoint: POST https://api.bitcoin.me/quotation
curl -X POST https://api.bitcoin.me/quotation \
-H "Content-Type: application/json" \
-d '{
"amountIn": "1000",
"tokenIn": "KLV",
"tokenOut": "KFI"
}'
Notes:
amountInmust be a stringtokenInandtokenOutmust be token asset IDs/tickers expected by the quotation API- Use the quotation response to set
amount_out_minwith common DEX slippage best practices (for example, apply a configurable slippage tolerance and never use zero protection in production)
- User selects input/output tokens and amount
- Frontend calls quotation API
- Frontend computes
amount_out_minbased on quote and slippage - Frontend submits
swaptransaction with your referral address, referral percentage, and user payment intoken_in - Contract executes swap and splits output
Swap with Referral
Executes a router swap and splits the final output between the referral address and the destination address.
How it works:
- Receives the swap parameters along with referral configuration
- Executes the swap through the router
- Calculates the referral fee from the total output
- Sends the referral amount to
referral_address - Sends the remaining amount to
amount_out_destination(or the caller if not provided)
Referral Fee Calculation:
referral_amount = amount_out_total * referral_percentage / 100000destination_amount = amount_out_total - referral_amount
Referral Percentage:
Uses a base of 100_000 — valid range is 100 (0.1%) to 5_000 (5.0%)
Payment: The input token amount to be swapped (sent as transaction value)
Request Body schema: application/jsonrequired
| scAddress required | string Referral contract address |
| funcName required | string Value: "swap" |
| args required | Array of strings Arguments:
|
Responses
Request samples
- Payload
{- "scAddress": "klv1qqqqqqqqqqqqqpgqjd9k34hzy53lsreq4drqkwfedqvtqen3x04sevtrjj",
- "funcName": "swap",
- "args": [
- "address:klv1referral_address_example",
- "u64:1000",
- "string:KLV",
- "string:KFI",
- "BigUint:950",
- "address:klv1destination_address_example"
], - "value": "KLV=1000"
}Response samples
- 200
{- "data": {
- "returnData": [
- "referral amount sent to referral_address",
- "user amount sent to destination"
], - "returnCode": "ok"
}
}