I am trying to work with Solana in Python and I am trying to send an SPL token.
The transaction successfully sends & I can see logger logging the HTTP request, however, I can’t get the response with the signature ID.
This is my code:
<code>transfer_spl_token:
# Initialize Solana client
client = Client(endpoint=SOLANA_ENDPOINT, commitment="processed")
transaction = Transaction()
# Get the associated token account address for the destination
associated_token_address = get_associated_token_address(dest_pubkey, mint_pubkey)
# Get our associated token account address for the source
source_associated_token_address = get_associated_token_address(source_pubkey, mint_pubkey)
logger.info(f"Source Associated Token Address: {source_associated_token_address}")
logger.info(f"Destination Associated Token Address: {associated_token_address}")
# Check if the associated token account exists
response = client.get_account_info(associated_token_address)
if response.value is None:
# Create associated token account instruction if it doesn't exist
create_ata_instruction = create_associated_token_account(
transaction.add(create_ata_instruction)
# Convert amount to smallest units
transfer_amount = int(amount * (10 ** decimals))
logger.info(f"Transfer amount in smallest units: {transfer_amount}")
# Add the token transfer instruction
program_id=TOKEN_PROGRAM_ID,
source=source_associated_token_address,
dest=associated_token_address,
owner=source_keypair.pubkey(),
response = client.send_transaction(transaction, source_keypair, opts=TxOpts(skip_confirmation=False, preflight_commitment="processed"))
<code>transfer_spl_token:
# Initialize Solana client
client = Client(endpoint=SOLANA_ENDPOINT, commitment="processed")
# Create transaction
transaction = Transaction()
# Get the associated token account address for the destination
associated_token_address = get_associated_token_address(dest_pubkey, mint_pubkey)
# Get our associated token account address for the source
source_associated_token_address = get_associated_token_address(source_pubkey, mint_pubkey)
logger.info(f"Source Associated Token Address: {source_associated_token_address}")
logger.info(f"Destination Associated Token Address: {associated_token_address}")
# Check if the associated token account exists
response = client.get_account_info(associated_token_address)
if response.value is None:
# Create associated token account instruction if it doesn't exist
create_ata_instruction = create_associated_token_account(
payer=source_pubkey,
owner=dest_pubkey,
mint=mint_pubkey
)
transaction.add(create_ata_instruction)
# Convert amount to smallest units
transfer_amount = int(amount * (10 ** decimals))
logger.info(f"Transfer amount in smallest units: {transfer_amount}")
# Add the token transfer instruction
transaction.add(
transfer_checked(
TransferCheckedParams(
program_id=TOKEN_PROGRAM_ID,
source=source_associated_token_address,
mint=mint_pubkey,
dest=associated_token_address,
owner=source_keypair.pubkey(),
amount=transfer_amount,
decimals=decimals
)
)
)
# Send transaction
response = client.send_transaction(transaction, source_keypair, opts=TxOpts(skip_confirmation=False, preflight_commitment="processed"))
logger.info(response)
</code>
transfer_spl_token:
# Initialize Solana client
client = Client(endpoint=SOLANA_ENDPOINT, commitment="processed")
# Create transaction
transaction = Transaction()
# Get the associated token account address for the destination
associated_token_address = get_associated_token_address(dest_pubkey, mint_pubkey)
# Get our associated token account address for the source
source_associated_token_address = get_associated_token_address(source_pubkey, mint_pubkey)
logger.info(f"Source Associated Token Address: {source_associated_token_address}")
logger.info(f"Destination Associated Token Address: {associated_token_address}")
# Check if the associated token account exists
response = client.get_account_info(associated_token_address)
if response.value is None:
# Create associated token account instruction if it doesn't exist
create_ata_instruction = create_associated_token_account(
payer=source_pubkey,
owner=dest_pubkey,
mint=mint_pubkey
)
transaction.add(create_ata_instruction)
# Convert amount to smallest units
transfer_amount = int(amount * (10 ** decimals))
logger.info(f"Transfer amount in smallest units: {transfer_amount}")
# Add the token transfer instruction
transaction.add(
transfer_checked(
TransferCheckedParams(
program_id=TOKEN_PROGRAM_ID,
source=source_associated_token_address,
mint=mint_pubkey,
dest=associated_token_address,
owner=source_keypair.pubkey(),
amount=transfer_amount,
decimals=decimals
)
)
)
# Send transaction
response = client.send_transaction(transaction, source_keypair, opts=TxOpts(skip_confirmation=False, preflight_commitment="processed"))
logger.info(response)
I’m calling this function here:
<code>async def confirm_buy:
signature = transfer_spl_token(deposit_address, user_address, token_amount, privkey, mint_address)
<code>async def confirm_buy:
# Transfer SPL token
signature = transfer_spl_token(deposit_address, user_address, token_amount, privkey, mint_address)
logger.info(signature)
</code>
async def confirm_buy:
# Transfer SPL token
signature = transfer_spl_token(deposit_address, user_address, token_amount, privkey, mint_address)
logger.info(signature)
This is what I see in my logger:
<code>- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- solanaweb3.rpc.httprpc.HTTPClient - INFO - Transaction sent to https://api.mainnet-beta.solana.com. Signature noZ2x.....AHwaX:
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 429 Too Many Requests"
<code>- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- solanaweb3.rpc.httprpc.HTTPClient - INFO - Transaction sent to https://api.mainnet-beta.solana.com. Signature noZ2x.....AHwaX:
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 429 Too Many Requests"
</code>
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- solanaweb3.rpc.httprpc.HTTPClient - INFO - Transaction sent to https://api.mainnet-beta.solana.com. Signature noZ2x.....AHwaX:
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 200 OK"
- httpx - INFO - HTTP Request: POST https://api.mainnet-beta.solana.com "HTTP/1.1 429 Too Many Requests"
I am new to Solana programming and not too sure what’s going on. Do I need to sign the transaction before sending it (so I have the txn ID already)?
I tried changing the commitment/pre-flight commitment.
I tried making the function async
I can’t get the response from send_transaction()
I was expecting to get signature