### Install Moonit SDK using npm or yarn Source: https://github.com/gomoonit/moonit-sdk/blob/main/README.md Instructions to install the `@moonit/sdk` package using either npm or yarn package managers. This is the first step to integrate the SDK into your project. ```shell npm i @moonit/sdk # or yarn add @moonit/sdk ``` -------------------------------- ### TypeScript Example: Creating a Token Mint Source: https://github.com/gomoonit/moonit-sdk/blob/main/README.md This TypeScript example demonstrates how to initialize the Moonit SDK and prepare a token mint transaction. It shows how to load a creator's Keypair and use the `prepareMintTx` function to gather all necessary data for minting, which then returns a transaction ready for signing. ```TypeScript import { CurveType, Environment, MigrationDex, Moonit, SolanaSerializationService, } from '@moonit/sdk'; import { Keypair } from '@solana/web3.js'; import testWallet from '../../test-wallet.json'; export const createMint = async (): Promise => { console.log('--- Create mint example ---'); const creator = Keypair.fromSecretKey(Uint8Array.from(testWallet)); console.log('Creator: ', creator.publicKey.toBase58()); const moonit = new Moonit({ rpcUrl: 'https://api.devnet.solana.com', environment: Environment.DEVNET, chainOptions: { solana: { confirmOptions: { commitment: 'confirmed' } }, }, }); const icon = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAMP2lDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnluSkEBoAQSkhN4EESkBpITQQu8IohKSAKHEGAgqdnRRwbWLCNjQVREFKyAWFLGzKPa+WFBQ1sWCXXmTArruK9873zf3/vefM/85c+7cMgConeCIRDmoOgC5wnxxTJAffXxSMp3UAxCAAgrAgDOHmydiRkWFAWhD57/buxvQG9pVe6nWP/v/q2nw+HlcAJAoiNN4edxciA8CgFdxReJ8AIhS3mxavkiKYQNaYpggxIulOEOOq6Q4TY73ynziYlgQtwGgpMLhiDMAUL0MeXoBNwNqqPZD7CjkCYQAqNEh9s7NncKDOBVia+gjgliqz0j7QSfjb5ppw5ocTsYwls9FZkr+gjxRDmfG/1mO/225OZKhGJawqWSKg2Okc4Z1u5U9JVSKVSDuE6ZFREKsCfEHAU/mDzFKyZQEx8v9UQNuHgvWDOhA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JvDMqbPMsy3nvM4dPe9x/vAFxoXGi64XG9pd2g/97v ``` -------------------------------- ### Generate and send a token buy transaction on Solana Devnet with Moonit SDK Source: https://github.com/gomoonit/moonit-sdk/blob/main/README.md This example demonstrates how to prepare and send a buy transaction for a token on Solana's devnet using the Moonit SDK. It covers initializing the SDK, fetching the current curve position, calculating the required collateral, preparing transaction instructions with slippage, setting a compute budget, and finally signing and sending the versioned transaction. ```typescript import { Environment, FixedSide, Moonit } from '@moonit/sdk'; import { ComputeBudgetProgram, Connection, Keypair, TransactionMessage, VersionedTransaction, } from '@solana/web3.js'; import testWallet from '../test-wallet.json'; export const buyIx = async (): Promise => { console.log('--- Buying token example ---'); const rpcUrl = 'https://api.devnet.solana.com'; const connection = new Connection(rpcUrl); const moonit = new Moonit({ rpcUrl, environment: Environment.DEVNET, chainOptions: { solana: { confirmOptions: { commitment: 'confirmed' } }, }, }); const token = moonit.Token({ mintAddress: '9ThH8ayxFCFZqssoZmodgvtbTiBmMoLWUqQhRAP89Y97', }); const curvePos = await token.getCurvePosition(); console.log('Current position of the curve: ', curvePos); // Prints the current curve position // make sure creator has funds const creator = Keypair.fromSecretKey(Uint8Array.from(testWallet)); console.log('Creator: ', creator.publicKey.toBase58()); const tokenAmount = 10000n * 1000000000n; // Buy 10k tokens // Buy example const collateralAmount = await token.getCollateralAmountByTokens({ tokenAmount, tradeDirection: 'BUY', }); const { ixs } = await token.prepareIxs({ slippageBps: 500, creatorPK: creator.publicKey.toBase58(), tokenAmount, collateralAmount, tradeDirection: 'BUY', fixedSide: FixedSide.OUT, // This means you will get exactly the token amount and slippage is applied to collateral amount }); const priorityIx = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 200_000, }); const blockhash = await connection.getLatestBlockhash('confirmed'); const messageV0 = new TransactionMessage({ payerKey: creator.publicKey, recentBlockhash: blockhash.blockhash, instructions: [priorityIx, ...ixs], }).compileToV0Message(); const transaction = new VersionedTransaction(messageV0); transaction.sign([creator]); const txHash = await connection.sendTransaction(transaction, { skipPreflight: false, maxRetries: 0, preflightCommitment: 'confirmed', }); console.log('Buy Transaction Hash:', txHash); }; ``` -------------------------------- ### Selling Tokens with Moonit SDK (TypeScript) Source: https://github.com/gomoonit/moonit-sdk/blob/main/README.md This TypeScript code snippet illustrates the complete flow for selling a specified amount of tokens using the Moonit SDK. It initializes the SDK, connects to the Solana devnet, retrieves the current curve position for the token, calculates the collateral amount, prepares the necessary transaction instructions with a defined slippage, and then builds and sends a versioned transaction. It uses a local `testWallet` for the creator's keypair and includes a compute unit price instruction for priority. ```typescript import { Environment, FixedSide, Moonit } from '@moonit/sdk'; import { ComputeBudgetProgram, Connection, Keypair, TransactionMessage, VersionedTransaction, } from '@solana/web3.js'; import testWallet from '../test-wallet.json'; export const sellIx = async (): Promise => { console.log('--- Selling token example ---'); const rpcUrl = 'https://api.devnet.solana.com'; const connection = new Connection(rpcUrl); const moonit = new Moonit({ rpcUrl, environment: Environment.DEVNET, chainOptions: { solana: { confirmOptions: { commitment: 'confirmed' } }, }, }); const token = moonit.Token({ mintAddress: '9ThH8ayxFCFZqssoZmodgvtbTiBmMoLWUqQhRAP89Y97', }); const curvePos = await token.getCurvePosition(); console.log('Current position of the curve: ', curvePos); // Prints the current curve position // make sure creator has funds const creator = Keypair.fromSecretKey(Uint8Array.from(testWallet)); console.log('Creator: ', creator.publicKey.toBase58()); const tokenAmount = 10000n * 1000000000n; // Buy 10k tokens // Buy example const collateralAmount = await token.getCollateralAmountByTokens({ tokenAmount, tradeDirection: 'SELL', }); const { ixs } = await token.prepareIxs({ slippageBps: 500, creatorPK: creator.publicKey.toBase58(), tokenAmount, collateralAmount, tradeDirection: 'SELL', fixedSide: FixedSide.IN, // This means you will pay exactly the token amount slippage is applied to collateral amount }); const priorityIx = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 200_000, }); const blockhash = await connection.getLatestBlockhash('confirmed'); const messageV0 = new TransactionMessage({ payerKey: creator.publicKey, recentBlockhash: blockhash.blockhash, instructions: [priorityIx, ...ixs], }).compileToV0Message(); const transaction = new VersionedTransaction(messageV0); transaction.sign([creator]); const txHash = await connection.sendTransaction(transaction, { skipPreflight: false, maxRetries: 0, preflightCommitment: 'confirmed', }); console.log('Sell Transaction Hash:', txHash); }; ``` -------------------------------- ### Minting a Token with Moonit SDK Source: https://github.com/gomoonit/moonit-sdk/blob/main/README.md This JavaScript code demonstrates the end-to-end process of minting a new token using the `@moonit/sdk`. It covers preparing the mint transaction with token metadata, deserializing and signing the transaction with a creator's key, and finally submitting the signed transaction to the network. It relies on `moonit` and `SolanaSerializationService`. ```JavaScript const prepMint = await moonit.prepareMintTx({ creator: creator.publicKey.toBase58(), name: 'SDK_MINT', symbol: 'SDK_MINT', curveType: CurveType.CONSTANT_PRODUCT_V1, migrationDex: MigrationDex.RAYDIUM, icon, description: 'Token minted using the @moonit/sdk', links: [{ url: 'https://x.com', label: 'x handle' }], banner: icon, tokenAmount: '42000000000' }); const deserializedTransaction = SolanaSerializationService.deserializeVersionedTransaction( prepMint.transaction, ); if (deserializedTransaction == null) { throw new Error('Failed to deserialize transaction'); } deserializedTransaction.sign([creator]); const signedTransaction = SolanaSerializationService.serializeVersionedTransaction( deserializedTransaction, ); const res = await moonit.submitMintTx({ tokenId: prepMint.tokenId, token: prepMint.token, signedTransaction, }); console.log(res); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.