pai-demo

0.3.2 • Public • Published

pai-demo: Solana Utility Functions for PAI Token Management

This package provides a set of TypeScript functions to interact with a Solana program for managing PAI tokens.

Requirements:

  • Node.js and npm (or yarn)
  • A Solana wallet with sufficient funds

Installation:

npm install pai-demo

Usage:

1. Import the functions:

import { createPaiTokenAccount, fundExistingAccount, getAllAccounts, handlePurchase } from "pai-demo";

2. Connect to Solana:

import { Connection, Keypair, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com"); // Replace with your endpoint
const payerWallet = Keypair.generate(); // Replace with your wallet

3. Use the functions:

a) createPaiTokenAccount:

Creates a new PAI token account for a user associated with a specific mint and payer wallet.

const userWallet = new PublicKey("..."); // Replace with user's public key
const mintPubkey = new PublicKey("..."); // Replace with mint public key

const tx = await createPaiTokenAccount(connection, userWallet, mintPubkey, payerWallet);

if (tx) {
  console.log("Transaction successful:", tx);
} else {
  console.error("Error creating token account");
}

b) fundExistingAccount:

Funds an existing PAI token account associated with a user, mint, and payer wallet.

const tx = await fundExistingAccount(connection, userWallet, mintPubkey, payerWallet);

if (tx) {
  console.log("Transaction successful:", tx);
} else {
  console.error("Error funding account");
}

c) getAllAccounts:

Retrieves all PAI token accounts associated with the provided payer wallet.

const accounts = await getAllAccounts(payerWallet);

if (accounts) {
  console.log("Found accounts:", accounts);
} else {
  console.error("Error fetching accounts");
}

d) handlePurchase:

Processes a PAI token purchase (implementation details depend on your program).

const tx = await handlePurchase(connection, userWallet, mintPubkey, payerWallet);

if (tx) {
  console.log("Transaction successful:", tx);
} else {
  console.error("Error handling purchase");
}

Note:

  • Replace placeholders like userWallet, mintPubkey, and wallet details with your actual values.
  • Ensure your program is deployed to a Solana network (devnet, testnet, mainnet) before using these functions.

Additional Notes:

  • Consider including error handling for all functions.
  • This is a basic example, and the exact implementation may vary based on your specific program and business logic.

Contributing:

We welcome contributions to improve this library. Please refer to the contribution guidelines (if available) before submitting any pull requests.

Readme

Keywords

none

Package Sidebar

Install

npm i pai-demo

Weekly Downloads

11

Version

0.3.2

License

none

Unpacked Size

44.3 kB

Total Files

15

Last publish

Collaborators

  • merrick17