Closed DanyLinuxoid closed 2 weeks ago
You can get this error from signing the tx with too many signers or not enough. You want to pass the transaction message to the signer and populate a transaction from it. Not suppose to use Transaction.Deserialize unless its a completed transaction that has already been signed.
Account trader = Account.FromSecretKey("");
Transaction swap = Transaction.Populate(Message.Deserialize(swapBytes));
bytes[] tx = swap.Build(trader);
//Send the tx byte array as a raw transaction to the rpc
Check out the c# client for Raydium. Available on nuget as well https://github.com/Bifrost-Technologies/Solnet.Raydium
Solnet.Raydium Quickstart:
using Solnet.Programs.Utilities;
using Solnet.Raydium.Client;
using Solnet.Raydium.Types;
using Solnet.Rpc;
using Solnet.Wallet;
IRpcClient connection = ClientFactory.GetClient("RPC LINK HERE");
RaydiumAmmClient raydiumAmmClient = new RaydiumAmmClient(connection);
Account trader = Account.FromSecretKey("SECRET KEY HERE");
//SOL in lamports as the amountIn
//Minimum out can be 0 to always execute no matter what or set it specifically to apply a fixed slippage rate
var swap_test = await raydiumAmmClient.SendSwapAsync(new PublicKey("POOL ADDRESS HERE"), SolHelper.ConvertToLamports(0.01m), 0, OrderSide.Buy, trader, trader);
Console.WriteLine(swap_test.RawRpcResponse.ToString());
Console.ReadKey();
Describe the bug I'm getting swap txn from an API, txn is already signed and I have to sign it on my end as well in order to submit to an rpc. But when I try to sign it in any way, I get "invalid transaction: Transaction failed to sanitize accounts offsets correctly"
To Reproduce From https://docs.bloxroute.com/solana/trader-api-v2/api-endpoints/raydium/create-swap-transaction-amm There is an example:
Which will return
My code that is failing in C#:
FULLY WORKING EXAMPLE (Private key, Public key, Rpc, and Authorization token should be filled)
Expected behavior Should not be getting "invalid transaction: Transaction failed to sanitize accounts offsets correctly"
Desktop (please complete the following information):
Additional context I'm successfully using Raydium + Jupiter + Jito + other API's to sign and execute transactions. But since this API is signing txn on it's own on their end, I'm having issues (for the first time).
If this is already known bug or something like that, then please guide me on how to resolve that and then issue can be closed.