The POST shortcuts/route API takes specification of DeFi route endpoints (the desired outcome) and returns a transaction object with calldata ready for on-chain submission. Enso analyzes protocols and costs in real-time to identify the most efficient route.

More than swaps!
This API handles entering lending positions on Aave or Compound, depositing into yield strategies like Yearn, adding liquidity to AMM pools like Uniswap, obtaining LP tokens from protocols like Curve, staking in governance, and converting wrapped assets.

Check out Shortcuts Library for more examples.

Route API Route API

Example

In this guide we’ll obtain optimal transaction to enter a Curve position from ETH.

The shortcuts/route API supports tokenized protocols, meaning you receive a token representing your position (like aTokens in Aave). To enter a non-tokenized position, use the GET route/nontokenized endpoint.

1

Authentication

  1. Create an API key using Enso Dashboard.
  2. Securely store your API key and make it available in your environment:
authentication.sh
ENSO_API_KEY="$ENSO_API_KEY"
echo $ENSO_API_KEY >> .env
git ignore .env
source .env
2

Get Optimal Path Calldata

To use the route API, you need to provide several parameters: input and output token, amount, slippage, and participating account addresses.

Set protocol parameter to enso when signing transactions through an EOA, and use delegatecall when signing through a smart wallet. Learn more about routing strategies.

CHAIN_ID=1
PROTOCOL=enso # TX will be sent to Enso Router

TOKEN_IN_ETH=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
TOKEN_OUT_stCRV=0x06325440d014e39736583c165c2963ba99faf14e
AMOUNT_IN=1000000000000000000
SLIPPAGE=300

FROM_ADDRESS=0xd8da6bf26964af9d7eed9e03e53415d37aa96045
RECEIVER=0xd8da6bf26964af9d7eed9e03e53415d37aa96045
SPENDER=0xd8da6bf26964af9d7eed9e03e53415d37aa96045

PATH_RESPONSE=$(curl -X 'POST' \
  "https://api.enso.finance/api/v1/shortcuts/route" \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $ENSO_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "chainId": "'$CHAIN_ID'",
    "fromAddress": "'$FROM_ADDRESS'",
    "receiver": "'$RECEIVER'",
    "spender": "'$SPENDER'",
    "amountIn": "'$AMOUNT_IN'",
    "slippage": "'$SLIPPAGE'",
    "tokenIn": "'$TOKEN_IN_ETH'",
    "tokenOut": "'$TOKEN_OUT_stCRV'",
    "routingStrategy": "'$STRATEGY'"
  }' \
  | jq)

TX=$(echo "$PATH_RESPONSE" | jq -r '.tx')
echo $PATH_RESPONSE | jq

The API response will contain:

  • route: A human-readable sequence of actions against supported protocols
  • tx: A transaction object with calldata—the executable form of the calculated route
  • amountOut: Expected output amount
  • gas: Estimated gas for the transaction
  • createdAt: Block number when the response was generated

The route response returns the tx object containing executable transaction data. The tx.data executes the optimal path and must be submitted directly to the EnsoShortcutRouter contract at the address specified in tx.to.

3

Send transaction on-chain

Use the result’s tx field to send the transaction on-chain.

TX=$(echo "$PATH_RESPONSE" | jq -r '.tx')
send_tx $TX # send_tx is a placeholder
4

Next steps

Updated

Was this page helpful?