### Install SundaeSwap and Blaze Cardano SDKs Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Installs the core SundaeSwap SDK and the Blaze Cardano SDK using Bun. These are essential dependencies for building swaps. Ensure you have a TypeScript and Webpack bundling setup. ```bash $ bun add @sundaeswap/core @blaze-cardano/sdk ``` -------------------------------- ### Setup Sundae SDK in Node.js Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core/node Initializes the SundaeSDK for Node.js environments by configuring Blaze, Blockfrost, and HotWallet. This setup is necessary because the SDK's default behavior assumes a browser context. It requires API keys and private keys for wallet and provider configuration. ```typescript import { Blaze, Blockfrost, HotWallet } from "@blaze-cardano/sdk"; import { ETxBuilderType, ISundaeSDKOptions, SundaeSDK } from "@sundaeswap/core"; // Get the API from the browser window. const myBlockfrostApiKey = ""; const provider = new Blockfrost({ network: "cardano-preview", projectId: myBlockfrostApiKey }); const blaze = Blaze.from( provider, await HotWallet.fromMasterkey( Core.Bip32PrivateKeyHex("your-private-key"), provider, Core.NetworkId.Testnet, ), ); const options: ISundaeSDKOptions = { wallet: { name: "eternl", network: "preview", blazeInstance, }, }; const SDK = SundaeSDK.new(options); ``` -------------------------------- ### Initialize Blaze Cardano SDK and SundaeSwap SDK Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Initializes the Blaze Cardano SDK with Blockfrost for network interaction and Eternl for wallet connection. It then instantiates the SundaeSDK with the configured Blaze instance. This setup is crucial for interacting with the blockchain and SundaeSwap. ```typescript import { Blaze, Blockfrost, WebWallet } from "@blaze-cardano/sdk"; import { ETxBuilderType, ISundaeSDKOptions, SundaeSDK } from "@sundaeswap/core"; // Get the API from the browser window. const myBlockfrostApiKey = ""; const api = await window.cardano.eternl.enable(); const blazeInstance = await Blaze.from( new Blockfrost({ network: network ? "cardano-mainnet" : "cardano-preview", projectId: myBlockfrostApiKey }), new WebWallet(api), ); const options: ISundaeSDKOptions = { blazeInstance, }; const SDK = await new SundaeSDK(options); const poolData = await SDK.query().findPoolData({ ident: "34c2b9d553d3a74b3ac67cc8cefb423af0f77fc84664420090e09990", }); ``` -------------------------------- ### Build and Sign SundaeSwap Transaction Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Builds the transaction using the previously obtained 'build' property and then signs it to prepare for submission. It returns methods for submitting the transaction and its CBOR representation. ```typescript // ... rest of our code const builtTx = await build(); const { submit, cbor } = await builtTx.sign(); ``` -------------------------------- ### Build V3 Swap Transaction with SundaeSwap SDK Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Initializes the SundaeSwap SDK builder for V3 contracts and calls the swap method with provided arguments. It returns properties for building and fee calculation. ```typescript // ...rest of our code const { build, fees } = await SDK.builder(EContractVersion.V3).swap(args); ``` -------------------------------- ### Utilize QueryProviderSundaeSwap Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core/node Demonstrates how to instantiate and use QueryProviderSundaeSwap to fetch specific pool data. It requires a network identifier ('preview') and the unique identifier of the pool. This provider allows querying for detailed pool information, such as liquidity and trading pairs. ```typescript import { QueryProviderSundaeSwap } from "@sundaeswap/core"; const queryProvider = new QueryProviderSundaeSwap("preview"); const ident = "...uniqueIdent..."; const result = await queryProvider.findPoolData({ ident }); ``` -------------------------------- ### Configure Swap Arguments for SundaeSwap Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Defines the arguments for a swap operation, including swap type (market order with slippage), pool data, destination address, and the amount of the supplied asset. This configuration is used to construct the swap transaction. ```typescript import { AssetAmount } from "@sundaeswap/asset"; import { // ...the previous imports ESwapType, EDatumType, ISwapConfigArgs, } from "@sundaeswap/core"; // ...rest of our previous code const args: ISwapConfigArgs = { swapType: { type: ESwapType.MARKET, slippage: 0.03, }, pool: poolData, orderAddresses: { DestinationAddress: { address: "...your address", datum: { type: EDatumType.NONE, }, }, }, suppliedAsset: new AssetAmount(25_000_000n, poolData.assetA), }; ``` -------------------------------- ### Submit Signed SundaeSwap Transaction Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Submits the signed transaction to the network and returns the transaction hash. This is the final step in sending the transaction. ```typescript const txHash = await submit(); ``` -------------------------------- ### Build Transactions for V1 Contracts with Lucid Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core/node Constructs transactions for V1 SundaeSwap contracts using TxBuilderLucidV1 and DatumBuilderLucidV1 from the @sundaeswap/core library. It requires an initialized Lucid instance and specifies the network for Datum building. This allows for performing swap operations via the built transaction. ```typescript import { TxBuilderLucidV1, DatumBuilderLucidV1 } from "@sundaeswap/core/lucid"; import { lucid } from "path/to/utils.ts"; const txBuilder = new TxBuilderLucidV1( lucid, new DatumBuilderLucidV1("preview") ); // Do your swap like normal. const result = await txBuilder.swap({ ...args }); ``` -------------------------------- ### Build Transactions for V3 Contracts with Lucid Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core/node Enables the construction of transactions for V3 SundaeSwap contracts using TxBuilderLucidV3 and DatumBuilderLucidV3. It depends on a pre-configured Lucid instance and the network identifier ('preview' in this case) for Datum construction, facilitating swap operations. ```typescript import { TxBuilderLucidV3, DatumBuilderLucidV3 } from "@sundaeswap/core/lucid"; import { lucid } from "path/to/utils.ts"; const txBuilder = new TxBuilderLucidV3( lucid, new DatumBuilderLucidV3("preview") ); // Do your swap like normal. const result = await txBuilder.swap({ ...args }); ``` -------------------------------- ### Import SundaeSwap SDK V3 Contract Version Source: https://sundaeswap-finance.github.io/sundae-sdk/guides/core Imports the necessary EContractVersion enum from the SundaeSwap core library to specify V3 contract usage. This is a prerequisite for interacting with V3 pools. ```typescript import { // ...rest of imports EContractVersion, } from "@sundaeswap/core"; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.