npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mosaic-ag/ts-sdk

v0.1.5

Published

### 1. Importing Required Modules

Downloads

87

Readme

Example of using Mosaic SDK to build a swap transaction on Aptos Movement

1. Importing Required Modules

First, we need to import the necessary modules and dependencies for the Aptos Movement blockchain transactions and swap data retrieval:

import { getSwapData } from '@mosaic-ag/ts-sdk';
import { Aptos, AptosConfig, Network, APTOS_COIN, Ed25519PublicKey, Ed25519PrivateKey, Account } from '@aptos-labs/ts-sdk';
import invariant from 'tiny-invariant';

2. Setting Up Constants

Next, define the constants that will be used throughout the script. These include wallet addresses, keys, and asset identifiers:

export const TEST_WALLET_ADDRESS = ''; // change me
export const TEST_PRIVATE_KEY = ''; // change me
export const TEST_PUBLIC_KEY = ''; // change me
export const USDC = '0x275f508689de8756169d1ee02d889c777de1cebda3a7bbcce63ba8a27c563c6f::tokens::USDC';
export const SLIPPAGE_BPS = 50;

3. Configuring Aptos Movement

Set up the configuration for the Aptos Movement blockchain network:

const aptosConfig = new AptosConfig({ network: Network.CUSTOM, fullnode: "https://aptos.testnet.suzuka.movementlabs.xyz/v1" })
export const aptos = new Aptos(aptosConfig);

4. Retrieving Swap Data

Retrieve the necessary swap data for the transaction using the getSwapData function:

const swapData = await getSwapData({
  tokenIn: APTOS_COIN,
  tokenOut: USDC,
  amountIn: '1000000',
  slippageBps: 50, // 0.5%
  feeRecipient: '0x24570782d195e458b6e67c52e373ad1c54e18b4ac41e7b4cd2cddec255e42ffb',
  feeBps: 50, // 0.5%
  chargeFeeBy: 'token_in', // token_in
});

5. Building the Transaction

Build a simple transaction with the swap data retrieved:

const transaction = await aptos.transaction.build.simple({
  sender: TEST_WALLET_ADDRESS,
  data: {
    function: swapData.function,
    functionArguments: swapData.functionArguments,
    typeArguments: swapData.typeArguments,
  },
});

6. Simulating the Transaction

Simulate the transaction to ensure it will succeed:

const simulateResponse = await aptos.transaction.simulate.simple({
  signerPublicKey: new Ed25519PublicKey(TEST_PUBLIC_KEY),
  transaction,
});

invariant(simulateResponse.length === 1, `unexpected error, simulateResponse = ${JSON.stringify(simulateResponse)}`);
invariant(simulateResponse[0].success, 'simulate failed');

7. Signing and Submitting the Transaction

Sign and submit the transaction using the private key:

const pendingTxResponse = await aptos.transaction.signAndSubmitTransaction({
  signer: Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(TEST_PRIVATE_KEY) }),
  transaction,
});

8. Waiting for Transaction Confirmation

Wait for the transaction to be confirmed on the blockchain:

const committedTxResponse = await aptos.transaction.waitForTransaction({ transactionHash: pendingTxResponse.hash });
invariant(committedTxResponse.success, 'transaction failed');

9. Logging the Transaction Result

Finally, log the success message with the transaction details:

console.log(`Success. https://explorer.movementnetwork.xyz/txn/${committedTxResponse.version}?network=testnet`);

Each block of code corresponds to a specific step in the process of setting up, building, simulating, signing, submitting, and confirming a transaction on the Aptos blockchain. This structure helps in understanding the flow and individual responsibilities of each part of the script.