This page provides detailed workflows for common operations with the Haiku Intents API suite. Each workflow includes example requests, responses, and a step-by-step guide for implementation.
Swap workflow: How to swap tokens using the API
Natural language swap: How to process a swap using the POST /buildIntentNaturalLanguage API
Scenario: A user seeks to swap 5 HONEY for USDC on Berachain.
Step 1: Check supporting tokens
Request:
curl -X GET "https://api.haiku.trade/v1/tokenList" \
-H "api-key: <YOUR_API_KEY>"
{
"unsigned_transaction": "0x123abc...",
"response": "Swapping 5 HONEY for USDC on Berachain."
}
Step 4: Finalise your transaction
Sign and broadcast the transaction using Ethers.js or any Web3 provider.
Scenario: The user wants to perform a multi-swap
Prompt: "Swap 100 HONEY for a portfolio of BERA, iBGT, USDC, and wBTC on Berachain"
Step 1: Build intent using natural language
cURL request:
curl -X POST "https://api.haiku.trade/v1/buildIntentNaturalLanguage" \
-H "Content-Type: application/json" \
-d '{
"wallet_positions": {
"bera:0xfcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce": 100
},
"prices": {
"bera:0xfcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce": 6.25
},
"intent": "Swap 100 HONEY for BERA, iBGT, USDC, and wBTC on Berachain"
}'
Example response:
{
"input_positions": {
"bera:0xfcbd14dc51f0a4d49d5e53c2e0950e0bc26d0dce": 100
},
"target_weights": {
"bera:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee": 0.25,
"bera:0x656b95e550c07a9ffe548bd4085c72418ceb1dba": 0.25,
"bera:0x549943e04f40284185054145c6e4e9568c1d3241": 0.25,
"bera:0x0555e30da8f98308edb960aa94c0db47230d2b9c": 0.25
},
"response": "Swapping 100 HONEY into an equal portfolio of BERA, iBGT, USDC, and wBTC on Berachain with the current price of BERA at $6.25."
}