# Directly Calling CrocSwapDex

The most gas efficient approach is for users to directly call the `CrocSwapDex` contract. However with the swap path upgrade, swappers must use the `userCmd()`function.

This method takes the same arguments as `swap()`but requires pre-formatting the arguments to the call into an ABI byte array. `userCmd()` should be called with a proxy index of 1 (the swap callapth) and the standard swap arguments ABI encoded.

### Solidity

```jsx
// Ethereum
address dex = 0xAaAaAAAaA24eEeb8d57D431224f73832bC34f688

uint16 SWAP_PROXY = 1

CrocSwapDex(dex).userCmd(SWAP_PROXY, abi.encode(
	base, 
  quote,
  poolIdx, 
  isBuy, 
  inBaseQty, 
  qty, 
  tip,
  limitPrice, 
  minOut,
  settleFlags));

------------------------------------------------------------
// Scroll
address dex = 0xAaAaAAAaA24eEeb8d57D431224f73832bC34f688

uint16 SWAP_PROXY = 1

CrocSwapDex(dex).userCmd(SWAP_PROXY, abi.encode(
	base, 
  quote,
  poolIdx, 
  isBuy, 
  inBaseQty, 
  qty, 
  tip,
  limitPrice, 
  minOut,
  settleFlags));
```

### Javascript

```jsx
const { ethers } = require('ethers');
import { AbiCoder } from "ethers/lib/utils";

const provider = new ethers.providers.JsonRpcProvider(...);

const routerAbi = ... // See below

const etherDexAddr = "0xAaAaAAAaA24eEeb8d57D431224f73832bC34f688"
const scrollDexAddr = "0xAaAaAAAaA24eEeb8d57D431224f73832bC34f688"

const contract = new ethers.Contract(etherRouterAddr, routerAbi, provider);

const abi = new ethers.utils.AbiCoder()
const cmd = abi.encode([
	"address", 
	"address", 
	"uint256", 
	"bool", 
	"bool", 
	"uint128", 
	"uint16", 
	"uint128", 
	"uint128", 
	"uint8"], 
[
	base, 
  quote,
  420, 
  isBuy, 
  inBaseQty, 
  qty, 
  0,
  limitPrice, 
  minOut,
  settleFlags])

contract.userCmd(1, cmd)
```

#### ABI

```jsx
[{
      "inputs": [
        {
          "internalType": "uint16",
          "name": "callpath",
          "type": "uint16"
        },
        {
          "internalType": "bytes",
          "name": "cmd",
          "type": "bytes"
        }
      ],
      "name": "userCmd",
      "outputs": [
        {
          "internalType": "bytes",
          "name": "",
          "type": "bytes"
        }
      ],
      "stateMutability": "payable",
      "type": "function"
    }]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ambient.finance/developers/dex-contract-interface/swaps/hot-path-swap-migration/directly-calling-crocswapdex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
