JSPM

solana-transactions-wrapper

2.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q52903F
  • License MIT

Handy tool to execute buy/sell transactions on the SOLANA chain

Package Exports

  • solana-transactions-wrapper
  • solana-transactions-wrapper/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (solana-transactions-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

solana-transactions-wrapper

Handy tool to execute buy/sell transactions on the SOLANA chain.

Installation

Install the package with npm:

npm install solana-transactions-wrapper

Usage

Importing the package

import { buy_token, sell_token, get_tokens } from 'solana-transactions-wrapper';

Buying a token

Parameters:

  • RPC_ENDPOINT: Your RPC endpoint to connect to.
  • WALLET_PRIVATE_KEY: The private key of the wallet you want to buy from.
  • ADDRESS_OF_TOKEN_TO_BUY: The address of the token you want to buy.
  • AMOUNT_OF_SOLANA_TO_SPEND: The amount of SOL you want to spend.
  • SLIPPAGE: The slippage you want to use (default 1%).

Usage:

await buy_token(
  RPC_ENDPOINT,
  WALLET_PRIVATE_KEY,
  ADDRESS_OF_TOKEN_TO_BUY,
  AMOUNT_OF_SOLANA_TO_SPEND,
  SLIPPAGE
);

Logs Example:

Connection established 🚀
Wallet fetched ✅
Trying to buy token using "amount" SOL...
Transaction sent with txid: "transaction_id"
Waiting for confirmation... 🕒
Transaction confirmed ✅

Selling a token

Parameters:

  • SELL_ALL: Boolean to decide wether to sell all or not. Defaults to true
  • RPC_ENDPOINT: Your RPC endpoint to connect to.
  • WALLET_PRIVATE_KEY: The private key of the wallet you want to sell from.
  • ADDRESS_OF_TOKEN_TO_SELL: The address of the token you want to sell.
  • AMOUNT_OF_TOKEN_TO_SELL: The amount of tokens you want to sell. (Include if SELL_ALL is false)
  • SLIPPAGE: The slippage you want to use (default 1%).

Usage:

await sell_token(
  SELL_ALL,
  RPC_ENDPOINT,
  WALLET_PRIVATE_KEY,
  ADDRESS_OF_TOKEN_TO_SELL,
  AMOUNT_OF_TOKEN_TO_SELL,
  SLIPPAGE,
);

Logs Example:

Connection established 🚀
Wallet fetched ✅
Selling "amount" of "token_address"...
Transaction sent with txid: "transaction_id"
Waiting for confirmation... 🕒
Transaction confirmed ✅

Getting Account Tokens Balances

const tokens_balances = await get_tokens_balances(
  RPC_ENDPOINT,
  WALLET_PRIVATE_KEY
);
  • RPC_ENDPOINT: Your RPC endpoint to connect to.
  • WALLET_PRIVATE_KEY: The private key of the wallet you want to get the tokens from.

This function returns a promise that resolves to an object mapping token addresses to their balance and symbol.


Getting Token Balance

const token_balance = await get_token_balance(
  RPC_ENDPOINT,
  WALLET_PRIVATE_KEY,
  TOKEN_ADDRESS
);
  • RPC_ENDPOINT: Your RPC endpoint to connect to.
  • WALLET_PRIVATE_KEY: The private key of the wallet you want to get the tokens from.
  • TOKEN_ADDRESS: The address of the token you want to get the balance from.

This function returns a promise that resolves to the balance of the token.