pumpfunsdk

package module
v0.0.0-...-11a2452 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Pump.fun Go SDK

Go

A SDK allowing you to create, buy and sell pump.fun tokens in Golang.

Installation

go get github.com/666pulse/pumpfun-go-sdk

Usage

package main

import (
	"log"
	"os"
	"context"

	// General solana packages.
	"github.com/gagliardetto/solana-go"
	"github.com/gagliardetto/solana-go/rpc"
	"github.com/gagliardetto/solana-go/rpc/ws"

	// Pump.fun Go SDK.
	pumpfunsdk "github.com/666pulse/pumpfun-go-sdk"
)

type Client struct {
	RpcClient *rpc.Client
	WsClient  *ws.Client
}

func getClient(rpcUrl string, wsUrl string) *Client {
	rpcClient := rpc.New(rpcUrl)
	wsClient, err := ws.Connect(context.Background(), wsUrl)
	if err != nil {
		log.Fatalln("ws connection error: ", err)
	}
	return &Client{RpcClient: rpcClient, WsClient: wsClient}
}

func main() {
	privateKey, err := solana.PrivateKeyFromBase58(os.Getenv("PRIVATE_KEY"))
	if err != nil {
		log.Fatalln("please set PRIVATE_KEY environment variable:", privateKey)
	}
	rpcURL := rpc.MainNetBeta_RPC
	wsURL := rpc.MainNetBeta_WS
	c := getClient(rpcURL, wsURL)
	mint := solana.NewWallet()
	_, err = pumpfunsdk.CreateToken(
		c.RpcClient,
		c.WsClient,
		privateKey,
		mint,
		"TEST", // symbol
		"TEST", // name
		"https://example.com", // metadata uri
		100000000, // buy 0.1 SOL
		200, // 2% slippage
	)
	if err != nil {
		log.Fatalln("can't create token:", err)
	}
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

BSD-3-Clause license, because FreeBSD is the best OS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuyToken

func BuyToken(
	rpcClient *rpc.Client,
	wsClient *ws.Client,
	user solana.PrivateKey,
	mint solana.PublicKey,
	buyAmountLamports uint64,
	slippageBasisPoint uint,
) (string, error)

buyToken buys a token from the bonding curve. The amount is the amount of tokens to buy, and the sol is the amount of SOL to pay. The mintAddr is the address of the mint of the token. This function will send a transaction to the network to buy the token. This function will return an error if the transaction fails.

func CreateToken

func CreateToken(rpcClient *rpc.Client, wsClient *ws.Client, user solana.PrivateKey, mint *solana.Wallet, name string, symbol string, uri string, buyAmountLamports uint64, slippageBasisPoint uint) (string, error)

func SellToken

func SellToken(
	rpcClient *rpc.Client,
	wsClient *ws.Client,
	user solana.PrivateKey,
	mint solana.PublicKey,
	sellTokenAmount uint64,
	slippageBasisPoint uint,
	all bool,
) (string, error)

func SetDevnetMode

func SetDevnetMode()

SetDevnetMode sets the pump.fun program addresses to the devnet addresses. It is important to call this function if you are using the devnet.

Types

type BondingCurveData

type BondingCurveData struct {
	RealTokenReserves    *big.Int
	VirtualTokenReserves *big.Int
	VirtualSolReserves   *big.Int
}

BondingCurveData holds the relevant information decoded from the on-chain data.

func (*BondingCurveData) String

func (b *BondingCurveData) String() string

type BondingCurvePublicKeys

type BondingCurvePublicKeys struct {
	BondingCurve           solana.PublicKey
	AssociatedBondingCurve solana.PublicKey
}

type CreateTokenMetadataRequest

type CreateTokenMetadataRequest struct {
	Filename    string
	Name        string
	Symbol      string
	Description string
	Twitter     string
	Telegram    string
	Website     string
}

type CreateTokenMetadataResponse

type CreateTokenMetadataResponse struct {
	Name        string `json:"name"`
	Symbol      string `json:"symbol"`
	Description string `json:"description"`
	ShowName    bool   `json:"showName"`
	CreatedOn   string `json:"createdOn"`
	Twitter     string `json:"twitter"`
	Telegram    string `json:"telegram"`
	Website     string `json:"website"`

	Image       string `json:"image"`
	MetadataUri string `json:"metadataUri"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL