Crates.io | pumpfun |
lib.rs | pumpfun |
version | 2.0.0 |
source | src |
created_at | 2024-11-18 02:47:58.338147 |
updated_at | 2024-11-22 15:50:22.49468 |
description | Rust SDK to interact with the Pump.fun Solana program. |
homepage | |
repository | https://github.com/nhuxhr/pumpfun-rs |
max_upload_size | |
id | 1451723 |
size | 82,557 |
The Pump.fun Solana Program SDK
is a Rust library that provides an interface for interacting with the Pump.fun Solana program. Pump.fun is a Solana-based marketplace enabling users to create and distribute their own tokens, primarily memecoins.
Add this crate to your project using cargo:
cargo add pumpfun
The main entry point is the PumpFun
struct which provides methods for interacting with the program:
Note: The SDK automatically creates Associated Token Accounts (ATAs) when needed during buy transactions. No manual ATA creation is required.
use anchor_client::{
solana_sdk::{
native_token::LAMPORTS_PER_SOL,
signature::{Keypair, Signature},
signer::Signer,
},
Cluster,
};
use pumpfun::{accounts::BondingCurveAccount, utils::CreateTokenMetadata, PriorityFee, PumpFun};
// Create a new PumpFun client
let payer: Keypair = Keypair::new();
let client: PumpFun<'_> = PumpFun::new(Cluster::Mainnet, &payer, None, None);
// Mint keypair
let mint: Keypair = Keypair::new();
// Token metadata
let metadata: CreateTokenMetadata = CreateTokenMetadata {
name: "Lorem ipsum".to_string(),
symbol: "LIP".to_string(),
description: "Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quam, nisi.".to_string(),
file: "/path/to/image.png".to_string(),
twitter: None,
telegram: None,
website: Some("https://example.com".to_string()),
};
// Optional priority fee to expedite transaction processing (e.g., 100 LAMPORTS per compute unit, equivalent to a 0.01 SOL priority fee)
let fee: Option<PriorityFee> = Some(PriorityFee {
limit: Some(100_000),
price: Some(100_000_000),
});
// Create token with metadata
let signature: Signature = client.create(&mint, metadata.clone(), fee).await?;
println!("Created token: {}", signature);
// Print amount of SOL and LAMPORTS
let amount_sol: u64 = 1;
let amount_lamports: u64 = LAMPORTS_PER_SOL * amount_sol;
println!("Amount in SOL: {}", amount_sol);
println!("Amount in LAMPORTS: {}", amount_lamports);
// Create and buy tokens with metadata
let signature: Signature = client.create_and_buy(&mint, metadata.clone(), amount_lamports, None, fee).await?;
println!("Created and bought tokens: {}", signature);
// Print the curve
let curve: BondingCurveAccount = client.get_bonding_curve_account(&mint.pubkey())?;
println!("{:?}", curve);
// Buy tokens (ATA will be created automatically if needed)
let signature: Signature = client.buy(&mint.pubkey(), amount_lamports, None, fee).await?;
println!("Bought tokens: {}", signature);
// Sell tokens (sell all tokens)
let signature: Signature = client.sell(&mint.pubkey(), None, None, fee).await?;
println!("Sold tokens: {}", signature);
The SDK is organized into several modules:
cpi
: Cross-program invocation interfacesaccounts
: Account structs for deserializing on-chain stateconstants
: Program constants like seeds and public keyserror
: Custom error types for error handlinginstruction
: Transaction instruction buildersutils
: Helper functions and utilitiesThe main PumpFun
struct provides high-level methods that abstract away the complexity of:
We welcome contributions! Please submit a pull request or open an issue to discuss any changes.
This project is licensed under either of the following licenses, at your option:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
This software is provided "as is," without warranty of any kind, express or implied. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Use at your own risk. The authors take no responsibility for any harm or damage caused by the use of this software. Users are responsible for ensuring the suitability and safety of this software for their specific use cases.
By using this software, you acknowledge that you have read, understood, and agree to this disclaimer.