-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to send solana or an spl wih latest version? #489
Comments
I dont care that priv key got leaked, it was a test wallet anyway |
i upgraded back to 0.32.2. Is there an example of sending sol or SPL tokens with it? |
no one click the link above, it will drain your wallet. |
Example to transfer SPL tokens:
Example to transfer SOL:
|
Thanks i got it working perfectly sending solana, but with SPL tokens it keeps saying I do not have balance, despite i do. I checked in debugs, it shows that the correct token account is being called, it shows the right balance, but when it sends it says it has 100x less: `import asyncio OPTS = TxOpts(skip_confirmation=False, preflight_commitment="processed") async def get_or_create_associated_token_account(client, payer_keypair, owner_pubkey, mint_pubkey):
async def send_sol_transaction(
Example usageif name == "main":
` |
@michaelhly I got both functions working, my main issue now is that i cannot get the SPL tokens to take a SOL fee. |
I am trying to send solana or tokens (depending on the contract_address parameter). The problem is, it doesnt take the priority fee into account.
I am using 0.27.0 because I was initially having problems sending transactions with the new api (Invalid base58 key when trying to send transactions).
I put it into chatgpt to fix it, but it made it worse.
Here it is:
`from spl.token.instructions import transfer_checked, create_associated_token_account, get_associated_token_address, TransferCheckedParams
from spl.token.constants import TOKEN_PROGRAM_ID
from solana.rpc.api import Client
from solana.rpc.types import TxOpts
from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.transaction import Transaction
from solana.system_program import transfer, TransferParams
import base58
import struct
import time
import random
List of multiple RPC endpoints for load balancing
RPC_ENDPOINTS = [
"https://magical-small-sun.solana-mainnet.quiknode.pro/1e7f2b948b444d55509c80ba0338c640e879a74a"
]
Rate limiter parameters
MAX_REQUESTS_PER_SECOND = 10 # Adjust based on RPC rate limits
request_count = 0
start_time = time.time()
def get_random_rpc_endpoint():
"""Select a random RPC endpoint for load balancing."""
return random.choice(RPC_ENDPOINTS)
def rate_limit():
"""Implements rate limiting to prevent exceeding RPC rate limits."""
global request_count, start_time
request_count += 1
elapsed_time = time.time() - start_time
if elapsed_time < 1.0: # Check if within the same second
if request_count > MAX_REQUESTS_PER_SECOND:
time.sleep(1.0 - elapsed_time) # Wait until 1 second has passed
else:
start_time = time.time()
request_count = 0
def send_transaction_with_retry(client, transaction, keypair, opts, max_retries=10):
"""
Sends a transaction with retry mechanism to handle rate limiting (429 errors) and unconfirmed transactions.
def confirm_transaction(client, tx_signature, commitment="finalized", max_retries=10):
"""
Manually checks the confirmation status of a transaction using get_signature_statuses.
def send_sol_transaction(senderPrivateKey, recipientAddress, contractAddress, amount, priorityfee):
"""
Sends Solana or a custom SPL token from the sender to the recipient.
Example usage
if name == "main":
sender_private_key = "PRIV" # Replace with actual sender private key
recipient_address = "RECPUB"
contract_address = "SOL" # Example SPL token mint address
amount = 0.0001 # Amount to send (in SOL)
priority_fee = 0.01 # Priority fee in SOL (will be converted to lamports)
`
The text was updated successfully, but these errors were encountered: