Package Exports
- @solsdk/tokenflow_sdk
Readme
@solsdk/tokenflow_sdk
A simple, type-safe, and robust SDK for interacting with Tokenflow on the Solana blockchain. This library provides a convenient interface for creating, buying, and selling tokens, as well as subscribing to protocol events.
Table of Contents
Features
- Create, buy, and sell tokens on Tokenflow with a single SDK.
- TypeScript-first, fully type-safe API (no
any, no type assertions). - Event subscription for protocol events (creation, trade, completion).
- Strict adherence to best practices: KISS, DRY, YAGNI, SOLID, RESTful, and more.
- Designed for Node.js (v20.9.0+) and browser environments (where supported).
Installation
npm install @solsdk/tokenflow_sdkQuick Start
Set up your environment:
- Create a
.envfile with your Solana RPC URL:HELIUS_RPC_URL=https://your-solana-rpc-url
- Create a
Basic usage:
import dotenv from "dotenv"; import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js"; import { DEFAULT_DECIMALS, HappyPumpSDK } from "@solsdk/tokenflow_sdk"; import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; import { AnchorProvider } from "@coral-xyz/anchor"; dotenv.config(); const provider = new AnchorProvider( new Connection(process.env.HELIUS_RPC_URL ?? ""), new NodeWallet(Keypair.generate()), { commitment: "finalized" } ); const sdk = new HappyPumpSDK(provider); // Example: create and buy a token const creator = Keypair.generate(); const mint = Keypair.generate(); const metadata = { name: "TST-7", symbol: "TST-7", description: "TST-7: This is a test token", filePath: "example/basic/random.png", }; await sdk.createAndBuy( creator, mint, metadata, BigInt(0.0001 * LAMPORTS_PER_SOL), 100n, { unitLimit: 250000, unitPrice: 250000 } );
API Reference
HappyPumpSDK
createAndBuy
Creates a new token and immediately buys it.
async createAndBuy(
creator: Keypair,
mint: Keypair,
createTokenMetadata: CreateTokenMetadata,
buyAmountSol: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment?: Commitment,
finality?: Finality
): Promise<TransactionResult>creator: Keypair of the token creator.mint: Keypair for the mint account.createTokenMetadata: Metadata for the token.buyAmountSol: Amount of SOL to spend.slippageBasisPoints: Slippage in basis points (default: 500).priorityFees: Optional priority fee settings.commitment: Solana commitment level.finality: Solana finality level.
buy
Buy tokens for a given mint.
async buy(
buyer: Keypair,
mint: PublicKey,
buyAmountSol: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment?: Commitment,
finality?: Finality
): Promise<TransactionResult>buyer: Keypair of the buyer.mint: PublicKey of the mint.buyAmountSol: Amount of SOL to spend.slippageBasisPoints: Slippage in basis points (default: 500).priorityFees: Optional priority fee settings.commitment: Solana commitment level.finality: Solana finality level.
sell
Sell a specified amount of tokens.
async sell(
seller: Keypair,
mint: PublicKey,
sellTokenAmount: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment?: Commitment,
finality?: Finality
): Promise<TransactionResult>seller: Keypair of the seller.mint: PublicKey of the mint.sellTokenAmount: Amount of tokens to sell.slippageBasisPoints: Slippage in basis points (default: 500).priorityFees: Optional priority fee settings.commitment: Solana commitment level.finality: Solana finality level.
addEventListener
Subscribe to protocol events.
addEventListener<T extends HappyPumpEventType>(
eventType: T,
callback: (event: HappyPumpEventHandlers[T], slot: number, signature: string) => void
): numbereventType: Type of event ("createEvent","tradeEvent","completeEvent").callback: Function to call on event.- Returns: Listener ID.
removeEventListener
Remove a previously registered event listener.
removeEventListener(eventId: number): voideventId: ID returned byaddEventListener.
Examples
Basic Example
Run the example to create, buy, and sell tokens:
npm run exampleEvent Subscription Example
Subscribe to protocol events:
const createEventId = sdk.addEventListener(
"createEvent",
(event, slot, signature) => {
console.log("createEvent", event, slot, signature);
}
);Contributing
Contributions are welcome! Please open an issue or submit a pull request to discuss changes or improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Disclaimer
This software is provided "as is," without warranty of any kind, express or implied. Use at your own risk. The authors are not responsible for any damages or losses resulting from the use of this software.
By following this README, you should be able to install the Tokenflow SDK, run the provided examples, and understand how to set up event listeners and perform token operations on the Tokenflow protocol.