Sell Tokens

Example code that would sell 100 percent of the current "MOGULMONEY" tokens I own

from solders.pubkey import Pubkey
from solana.rpc.api import Client
from solders.keypair import Keypair

import solcoin.sell_tokens as sell

PUBLIC_KEY = "your_account_pubkey_string" # ex:G3tmXiWmgnhhjb4N12YK7QgmaqtRaCRaL6i4nx2ueKwr
TOKEN_MINT = "token_mint_string" # ex:6oDn2PDvjtKYoWVp9cNNe1WCepjS8VQzhBRS8qmXpump
mint_pubkey = Pubkey.from_string(TOKEN_MINT)
client = Client("your_RPC_url") # ex:https://api.mainnet-beta.solana.com

tokensOrSolAmount = 100 # how many tokens or sol or percent of coins you own you want to purchase
tokensOrSol = 'percent' # either 'token' or 'sol' or 'percent, whichever unit you want to buy in
SLIPPAGE_PERCENT = 20
PRIORITY_FEE = .000001 

private_key_base58 = "private_key_base58_string" # your base58 private key string
payer_keypair = Keypair.from_base58_string(private_key_base58)


sig, status = sell.sell_token(mint_pubkey, client, tokensOrSolAmount, tokensOrSol, SLIPPAGE_PERCENT, PUBLIC_KEY, payer_keypair, PRIORITY_FEE)


print(sig) # prints the signature of the transaction
print(status) # prints the current status of the transaction
  • PUBLIC_KEY = The public key of the account you are using to purchase the tokens, make sure this account has enough sol in it to cover fees and pay for rent

  • TOKEN_MINT = the mint pubkey of the token you are trying to purchase

  • client = the rpc client you are using, replace the rpc_url with your rpc provider's url

  • TokensOrSolAmount = the amount of tokens you want to sell or sol you want to sell or percent you want to sell; depends on the value of tokensOrSol

  • TokensOrSol = what unit you are buying either 'token' or 'sol' or 'percent'

  • SLIPPAGE_Percent = % price slippage for transaction to still proceed

  • PRIORITY_FEE = fee paid divided among 150k compute units

  • private_key_base58 = the private key string of the account you are using to purchase the tokens.

Last updated