Execute a Swap

Use the response from the previous step to perform a swap

As outlined in the previous page, the /routes endpoint will return data with the shape of:

interface ReturnData {
    expectedOut: string,
    routerAddress: Address,
    details: {
        path: Address[],
        pairs: Address[],
        extras: string[],
        inputAmount: BigNumberString,
        expectedOutputAmount: BigNumberString,
        deadline: number,
        partner: number,
        sig: string
    }
}

type Address = string
type BigNumberString = string 

For executing a swap, every field that is needed is contained within the details object.

Here is a breakdown of the details object:

The details purposefully details the struct recognized by the Swap router as SwapPayload. This struct looks like:

struct SwapPayload {
		address[] path;
		address[] pairs;
		bytes[] extras;
		uint256 inputAmount;
		uint256 minOutputAmount;
		uint256 expectedOutputAmount;
		address to;
		uint deadline;
		uint256 partner;
		bytes sig;
	}
function swapExactInputForOutput(
		SwapPayload calldata details
	) external returns (uint256 outputAmount);

Once the transaction has been created, use the user's preferred wallet provider to sign the transaction and send it to be committed on chain.

Last updated