1. Get a Quote via Kernel SDK
Use the Kernel SDK to fetch a swap quote that references the canonical hub state.Copy
import { getSwapQuote, EnvMode } from "@skate-org/skate-app-amm";
// change id accordingly
const chainId = 901
const quote = await getSwapQuote(
chainId,
{
tokenA: tokenIn,
tokenB: tokenOut,
slippageLimit: 0.001,
amount: BigInt(userAmount),
},
"PRODUCTION" as EnvMode
);
2. Execute Swap via Periphery SDKs
Execute the quote using the periphery SDK corresponding to your target chain:Copy
import { privateKeyToAccount } from "viem/accounts";
import {
createPublicClient,
Chain,
http,
createWalletClient,
WalletClient,
Account,
defineChain,
} from "viem";
import { peripheryPoolAdapter } from "@skate-org/skate-app-amm";
const account = privateKeyToAccount(PRIVATE_KEY as `0x${string}`);
const wallet = createWalletClient({
chain,
account,
transport: http(RPC_URL),
});
const recipient = RECIPIENT_ADDRESS; // in bytes32 format
const swapData: `0x${string}` = peripheryPoolAdapter.getSwapCalldata({
recipient: evmContext!.account!.address as `0x${string}`,
destChainId: chainId,
destVmType: 1,
amount: amount,
zeroForOne: zeroForOne,
sqrtPriceLimitX96: sqrtPriceLimitX96,
minAmountOut: minAmountOut,
});
const executableRequest = await wallet.prepareTransactionRequest({
account: account,
chain: wallet.chain,
data: swapData,
to: poolAddress,
});
const signedTx = await wallet.signTransaction(executableRequest);
const tx = await wallet.sendRawTransaction({
serializedTransaction: signedTx,
});
return tx;