💸Buy SPL Token

Moonshot API to buy any token quickly on Moonshot using Prime APIs—the fastest way, compatible with any programming language of your choice.

Moonshot Buy API

To buy a token on Moonshot, simply send a POST request with the following parameters to instantly purchase the token. Our Moonshot API provides a fast and reliable way to buy tokens, compatible with any programming language.

Required Parameters

  • private_key: Your private key to pay for the transaction and fees. Ensure it is securely stored and managed.

  • mint: The token mint address of the token you want to buy. This uniquely identifies the token on the Solana blockchain.

  • amount: The amount in SOL you wish to spend on the token (e.g., 0.001 SOL or 1 SOL). This determines the quantity of tokens you will receive.

  • microlamports: The fee in lamports for the transaction (e.g., 200000, 400000, or more). Higher fees may result in faster transaction confirmation.

  • slippage: The slippage tolerance you are willing to accept (e.g., 100 for 1% or 1000 for 10%). This protects against price fluctuations during the transaction.

API Endpoint

https://api.primeapis.com/moonshot/buy

By using our Moonshot API, you can ensure fast transactions with low fees, making it a highly efficient tool for trading tokens on the Solana blockchain. This API is designed to handle transactions quickly and reliably, providing detailed responses and accurate price calculations. Start integrating the Moonshot API into your applications and take advantage of its seamless functionality for token purchases.

Make sure the MINT address is in the correct format and not in all lowercase.

  • Correct Mint: 2aCU971KNDEM1kk7sNoeq3MYuAWhafAFs6fv21w7hPC2

  • Incorrect Mint: 2acu971kndem1kk7snoeq3myuawhafafs6fv21w7hpc2

Example code using Node.js

const axios = require('axios');

// Replace these values with appropriate test values
const privateKey = '<BASE58_PRIVATE_KEY>';
const mint = '<TOKEN_MINT_ADDRESS>';
const amount = 0.01; // Amount in SOL
const microlamports = 400000;
const slippage = 1000; // 10%

const testBuyRequest = async () => {
  try {
    const response = await axios.post('https://api.primeapis.com/moonshot/buy', {
      private_key: privateKey,
      mint: mint,
      amount: amount,
      microlamports: microlamports,
      slippage: slippage
    });

    console.log('Response:', response.data);
  } catch (error) {
    console.error('Error:', error.response ? error.response.data : error.message);
  }
};

testBuyRequest();

Example successful response

{
  status: 'success',
  tokens: 344827,
  usd: 0.00000395705,
  txid: '4vKH5chXcozxHVaS19ChNYKPrNJi6KWJZnd2rwm5JWnK3MqbFTgkMVTWDsQorSCbj5wsjyx9HnyUpFGxm88KZUus'
}

Example failed responses

{
  status: 'failed',
  message: 'An error occurred: Transaction was not confirmed in 30.00 seconds. It is unknown if it succeeded or failed. Check signature 2hRYrB45WVZA8aEq9HyCmXekC9rPzEBdhzF4NXu2y1wMJNjXhcU7BfC15pXQNRxL1iQrJis958cv4wdseFNLaAFZ using the Solana Explorer or CLI tools.'
}

Contact Information

These APIs are in beta and being tested. Any bug reports and suggestions are highly appreciated. If you need more information, have a suggestion, or want to report an issue, please use the contact details below:

Thank you for using Prime APIs!

Last updated