Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

swapExactAmountOut

Submit an instant swap with an exact output amount. Excess input is refunded.

Signature

function swapExactAmountOut(
  client: Client<Signer>,
  parameters: {
    sender: Address
    route: SwapRoute
    output: Coin
    input: Coin
  },
): Promise<{ hash: Uint8Array } & TxData>

Example

import { createSignerClient, createTransport, testnet, PrivateKeySigner } from "@left-curve/sdk"
import type { Address } from "@left-curve/sdk"
 
const client = createSignerClient({
  chain: testnet,
  transport: createTransport(),
  signer: PrivateKeySigner.fromMnemonic(process.env.DANGO_MNEMONIC!),
})
const sender: Address = "0x1234567890abcdef1234567890abcdef12345678"
 
await client.swapExactAmountOut({
  sender,
  input: { denom: "dango", amount: "2100000000" }, // generous bound
  output: { denom: "bridge/usdc", amount: "100000000" },
  route: [{ baseDenom: "dango", quoteDenom: "bridge/usdc" }],
})

Parameters

senderAddress. The trader.

routeSwapRoute. Array of PairId hops.

outputCoin. Exact output { denom, amount }.

inputCoin. Maximum input to send. Unused input is refunded.

Returns

{ hash: Uint8Array } & TxData — see broadcastTxSync.

See also