2024-12-31 16:51:58 +08:00
# PumpFun Rust SDK
A comprehensive Rust SDK for seamless interaction with the PumpFun Solana program. This SDK provides a robust set of tools and interfaces to integrate PumpFun functionality into your applications.
# Explanation
2025-04-02 14:03:56 +08:00
1. Add `create, buy, sell` for pump.fun.
2. Add `logs_subscribe` to subscribe the logs of the PumpFun program.
3. Add `yellowstone grpc` to subscribe the logs of the PumpFun program.
4. Add `jito` to send transaction with Jito.
5. Add `nextblock` to send transaction with nextblock.
6. Add `0slot` to send transaction with 0slot.
7. Submit a transaction using Jito, Nextblock, and 0slot simultaneously; the fastest one will succeed, while the others will fail.
2025-01-03 11:14:39 +08:00
## Usage
2025-04-02 14:25:30 +08:00
```shell
cd ` your project root directory`
git clone https://github.com/MiracleAI-Labs/pumpfun-sdk
```
```toml
# add to your Cargo.toml
pumpfun-sdk = { path = "./pumpfun-sdk" , version = "2.4.3" }
```
2025-01-03 11:14:39 +08:00
### logs subscription for token create and trade transaction
```rust
2025-04-09 13:36:15 +08:00
use pumpfun_sdk ::{ common ::logs_events ::PumpfunEvent , grpc ::YellowstoneGrpc };
2025-01-03 11:14:39 +08:00
2025-04-02 14:03:56 +08:00
// create grpc client
let grpc_url = "http://127.0.0.1:10000" ;
let client = YellowstoneGrpc ::new ( grpc_url );
2025-01-03 11:14:39 +08:00
// Define callback function
2025-04-02 14:03:56 +08:00
let callback = | event : PumpfunEvent | {
2025-01-03 11:14:39 +08:00
match event {
2025-04-02 14:03:56 +08:00
PumpfunEvent ::NewToken ( token_info ) => {
2025-01-03 11:14:39 +08:00
println! ( "Received new token event: {:?} " , token_info );
},
2025-04-02 14:03:56 +08:00
PumpfunEvent ::NewDevTrade ( trade_info ) => {
println! ( "Received dev trade event: {:?} " , trade_info );
},
PumpfunEvent ::NewUserTrade ( trade_info ) => {
2025-01-03 11:14:39 +08:00
println! ( "Received new trade event: {:?} " , trade_info );
},
2025-04-02 14:03:56 +08:00
PumpfunEvent ::NewBotTrade ( trade_info ) => {
2025-01-03 17:06:19 +08:00
println! ( "Received new bot trade event: {:?} " , trade_info );
}
2025-04-02 14:03:56 +08:00
PumpfunEvent ::Error ( err ) => {
2025-01-03 11:14:39 +08:00
println! ( "Received error: {} " , err );
}
}
};
2025-04-02 14:03:56 +08:00
let payer_keypair = Keypair ::from_base58_string ( "your private key" );
client . subscribe_pumpfun ( callback , Some ( payer_keypair . pubkey ())). await ? ;
2025-01-03 11:14:39 +08:00
```
2025-04-09 13:38:19 +08:00
### Init pumpfun instance for configs
2025-01-03 11:14:39 +08:00
```rust
2025-04-09 13:36:15 +08:00
use std ::sync ::Arc ;
use pumpfun_sdk ::{ common ::{ Cluster , PriorityFee }, PumpFun };
use solana_sdk ::{ commitment_config ::CommitmentConfig , signature ::Keypair , signer ::Signer };
2025-01-23 17:48:10 +08:00
2025-04-09 13:36:15 +08:00
let priority_fee = PriorityFee {
2025-04-10 11:04:55 +08:00
unit_limit : 190000 ,
2025-04-09 13:36:15 +08:00
unit_price : 1000000 ,
buy_tip_fee : 0.001 ,
sell_tip_fee : 0.0001 ,
};
let cluster = Cluster {
rpc_url : "https://api.mainnet-beta.solana.com" . to_string (),
block_engine_url : "https://block-engine.example.com" . to_string (),
nextblock_url : "https://nextblock.example.com" . to_string (),
nextblock_auth_token : "nextblock_api_token" . to_string (),
zeroslot_url : "https://zeroslot.example.com" . to_string (),
zeroslot_auth_token : "zeroslot_api_token" . to_string (),
use_jito : true ,
use_nextblock : false ,
use_zeroslot : false ,
2025-04-02 14:03:56 +08:00
priority_fee ,
2025-04-09 13:36:15 +08:00
commitment : CommitmentConfig ::processed (),
};
// create pumpfun instance
let payer = Keypair ::from_base58_string ( "your private key" );
let pumpfun = PumpFun ::new (
Arc ::new ( payer ),
& cluster ,
). await ;
```
2025-04-09 13:38:19 +08:00
### pumpfun create Token
2025-04-09 13:36:15 +08:00
```rust
use std ::sync ::Arc ;
use pumpfun_sdk ::{ ipfs , PumpFun };
use solana_sdk ::{ native_token ::sol_to_lamports , signature ::Keypair , signer ::Signer };
// create pumpfun instance
let pumpfun = PumpFun ::new ( Arc ::new ( payer ), & cluster ). await ;
// Mint keypair
let mint_pubkey : Keypair = Keypair ::new ();
let metadata = ipfs ::CreateTokenMetadata {
name : "Doge" . to_string (),
symbol : "DOGE" . to_string (),
description : "Dogecoin" . to_string (),
file : "/Users/joseph/Desktop/doge.png" . to_string (),
twitter : None ,
telegram : None ,
website : None ,
metadata_uri : None ,
};
2025-04-10 11:04:55 +08:00
// ipfs jwt_token for https://pinata.cloud
let jwt_token = "your ipfs jwt_token" ;
let ipfs_metadata = ipfs ::create_token_metadata ( metadata , & jwt_token ). await ? ;
2025-04-09 13:36:15 +08:00
println! ( "ipfs_metadata: {:?} " , ipfs_metadata );
pumpfun . create_and_buy (
mint ,
ipfs_metadata ,
sol_to_lamports ( 0.1 ),
None ,
). await ? ;
```
2025-04-09 13:38:19 +08:00
### pumpfun buy token
2025-04-09 13:36:15 +08:00
```rust
use pumpfun_sdk ::PumpFun ;
use solana_sdk ::{ native_token ::sol_to_lamports , signature ::Keypair , signer ::Signer };
2025-01-03 11:14:39 +08:00
2025-04-02 14:03:56 +08:00
// create pumpfun instance
let pumpfun = PumpFun ::new ( Arc ::new ( payer ), & cluster ). await ;
2025-01-03 11:14:39 +08:00
// Mint keypair
2025-04-02 14:03:56 +08:00
let mint_pubkey : Keypair = Keypair ::new ();
2025-01-03 11:14:39 +08:00
2025-04-02 14:03:56 +08:00
// buy token with tip
pumpfun . buy_with_tip ( mint_pubkey , 10000 , None ). await ? ;
2025-01-03 11:14:39 +08:00
2025-04-09 13:36:15 +08:00
```
2025-04-09 13:38:19 +08:00
### pumpfun sell token
2025-04-09 13:36:15 +08:00
```rust
use pumpfun_sdk ::PumpFun ;
use solana_sdk ::{ native_token ::sol_to_lamports , signature ::Keypair , signer ::Signer };
// create pumpfun instance
let pumpfun = PumpFun ::new ( Arc ::new ( payer ), & cluster ). await ;
// sell token with tip
pumpfun . sell_with_tip ( mint_pubkey , 100000 , None ). await ? ;
2025-04-02 14:03:56 +08:00
// sell token by percent with tip
pumpfun . sell_by_percent_with_tip ( mint_pubkey , 100 , None ). await ? ;
2025-01-03 11:14:39 +08:00
```