A fully coded Python bot directly interacting with the pump.fun programs & accounts, not relying on any 3rd party APIs
trade.py
implementation.
config.py
file.
The coin related variables that are necessary for constructing transactions are:
mint
— the created token addressbondingCurve
— the bonding curve account created for the newly minted token; this is the account that defines the token priceassociatedBondingCurve
— the associated account that’s holding the tokens that you buy and sell per the bonding curve token price information; the mechanism here is the default Solana one, which is the same thing as how you need an associated token account as a user to hold a tokenmint
, bondingCurve
, and associatedBondingCurve
), the bot uses the blockSubscribe | Solana method over WebSocket with full transaction details, filters out the transactions are 1) only related to the main pump.fun executable program 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
and 2) that only match the create
instruction.
Then from the those transactions, the bot extracts the required addresses.
config.py
and the coin specific ones from the listener script.
Then using the mint
address and the end user address (from your private key), the bot creates an associated token account to be able to hold the tokens.
Then the bot fetches the token price from the bondingCurve
account.
And then the bot does the purchase.
A couple of notes:
learning-examples/calculate_discriminator.py
blockSubscribe
method) is also up there in the speed league, so when it comes to doing the actual write transactions, not all of the data that we already have may have fully propagated across the cluster, so you might get an error as a result. Feel free to experiment with this cooldown setting.trade.py
. This is the script that puts together the listener script, the buy script, and the sell script.
trades
directory keeps the tab on your listens and trades:
trades.log
is an appendable file that adds each of your trades (buy/sell), along with the token address and a time stamp.learning-examples
directory that should help you understand how the bot is constructed and how to interact with Solana in general, so be sure to check it out.
Examples:
blockSubscribe_extract_transactions.py
— connects over WebSocket, subscribes with blockSubscribe | Solana, and dumps all the extracted transactions in raw form to the learning-examples/blockSubscribe-transactions
directorycalculate_discriminator.py
— calculates the unique discriminator as part of the Anchor framework for the pump.fun instructions. The instructions themselves can be taken from the idl/pump_fun_idl.json
filefetch_price.py
— a full implementation of doing a getAccountInfo
call to a token’s bonding curve address and then decoding the responsedecode_from_blockSubscribe.py
— decodes the raw transactions extracted with the blockSubscribe
methoddecode_from_getAccountInfo.py
— decodes the raw response from the getAccountInfo
call to a token’s bonding curve address; this is how you fetch the token pricelisten_create_from_blocksubscribe.py
— this is basically blockSubscribe_extract_transactions.py
but with all the additional parsing to keep printing the newly minted token data to youlisten_new_direct.py
— uses logsSubscribe | Solana to print the parsed token data from the pump.fun program logs; this is here as an example but it is not used in our bot as the logs do not emit the associatedBondingCurve
addresslisten_new_portal.py
— just an example of getting the newly minted token data stream from a third-party API like pumpportal; not used in our botmanual_buy.py
— a manual buy script; you provide all the necessary parametersmanual_sell.py
— a manual sell script; you provide all the necessary parameterstrade.py
script, which is the bot itself, with a few flags:
--yolo
— keeps the bot running in continuous mode; the bot buys a token, sells the token 20 seconds later, and then buys a new one--match
— trades the tokens with names or symbols matching this string you provide--bro
— only buys and sells the tokens created by a certain user address--marry
— makes the script buy a token and never sellpython trade.py --match doge --bro 7YmjpX4sPPw9pq6P2hrq9LehAi6QjELPWZYKXRrLaLCB --marry
will only buy the tokens that have doge
in the name or description, created by the user 7YmjpX4sPPw9pq6P2hrq9LehAi6QjELPWZYKXRrLaLCB
and never sell the tokens.