Troubleshooting
When working with the SolanaPortal API and the provided swapping script, you might encounter various errors or issues during execution. Below is a detailed guide on common problems, their potential causes, and steps to resolve them.
Error: Invalid or Incorrect Private Key
Symptom:
The script throws an error like:
Invalid private key
orError during swap: Invalid secret key length
.
Cause:
The private key provided in the
private_key
variable is incorrect, improperly formatted, or incomplete.
Resolution:
Ensure that the private key is in Base58 format.
Double-check that you are not accidentally truncating or miscopying the key.
Validate the private key by decoding it with
bs58.decode(private_key)
and ensuring no errors occur.
Wallet Address Not Matching the Private Key
Symptom:
The
wallet.publicKey.toBase58()
doesn't match the expected wallet address.
Cause:
The private key provided does not correspond to the intended wallet.
Resolution:
Use a key management tool to verify the private key's corresponding public key.
Confirm that the wallet address aligns with your intended trading account.
API Returns Non-200 Status
Symptom:
The script logs
API Error:
followed by the response status or status text, such asBad Request
.
Cause:
The request sent to the SolanaPortal API (
https://api.solanaportal.io/api/trading
) contains invalid or incomplete parameters.
Resolution:
Double-check the request payload (
param
object) for errors:wallet_address: Ensure it matches the wallet's public key.
action: Must be
buy
orsell
.mint: Verify that the mint address corresponds to the correct token.
dex: Ensure the specified DEX (
raydium
,jupiter
, etc.) is supported.amount: Provide a valid and precise amount to trade.
slippage: Set slippage tolerance appropriately (in numbers, e.g., 90 ).
tip: Set a valid tip value.
type: Must be
jito
for Jito transactions.
Transaction Fails After Signing
Symptom:
The script logs
Transaction failed. Please check the parameters.
after sending the transaction to Jito.
Cause:
The signed transaction is invalid, incorrectly serialized, or rejected by the Jito block engine.
Resolution:
Verify transaction signing:
Ensure the wallet's private key is correctly used to sign the transaction.
Confirm that
txn.sign([wallet])
properly signs the transaction.
Debug the serialized transaction:
Check network compatibility:
Ensure that the API endpoint (
https://tokyo.mainnet.block-engine.jito.wtf/api/v1/transactions
) is active and accessible.Validate that your Solana RPC node is not experiencing connectivity issues.
Signature Not Found on Solscan
Symptom:
The transaction is marked as succeeded, but the signature URL on Solscan shows
Transaction Not Found
.
Cause:
The transaction has not been confirmed on the Solana blockchain.
Resolution:
Monitor the transaction status:
Use Solana's CLI or another explorer to track the transaction:
Increase confirmation time:
Transactions might take longer to finalize during network congestion. Wait and recheck after a few minutes.
Double-check your RPC node:
Ensure the Jito endpoint is correctly configured and functional.
Incorrect Dex or Mint Address
Symptom:
The swap fails due to unsupported DEX or an invalid token mint address.
Cause:
The DEX or token mint specified in the parameters is not valid or does not support the desired action.
Resolution:
Verify the DEX:
Ensure you are using one of the supported platforms (
raydium
,jupiter
,pumpfun
,moonshot
).
Validate the token mint:
Use a token explorer (e.g., Solscan) to confirm the mint address's validity and availability on the selected DEX.
Slippage Too High or Too Low
Symptom:
The API rejects the request due to an invalid slippage setting.
Cause:
Slippage tolerance is either too restrictive or excessively high.
Resolution:
Adjust the slippage parameter:
Use a value between 50 and 100 depending on market volatility.
Test with smaller slippage values and gradually increase if the trade fails.
Debugging Tips
Log Everything: Print detailed logs for the request and response to identify issues:
Test Isolated Components: Test signing, transaction creation, and API calls separately to pinpoint errors.
Use a Test Wallet: Perform testing with a wallet that contains minimal funds to avoid potential loss.
Last updated