I am trying to execute a swap on jupiter in Python. My code looks like
tokenIn = Pubkey.from_string('So11111111111111111111111111111111111111112')
tokenOut = Pubkey.from_string('Fch1oixTPri8zxBnmdCEADoJW2toyFHxqDZacQkwdvSP')
amountIn = 0.4
slippageBps = 1000
quoteResponse = requests.get(
f"https://quote-api.jup.ag/v6/quote?inputMint={tokenIn}\
&outputMint={tokenOut}\
&amount={int(amountIn * 10**decimalsIn):d}\
&swapMode=ExactIn\
&slippageBps={slippageBps}\
&platformFeeBps=20"
).json()
payload = json.dumps({
"userPublicKey": str(source),
"wrapAndUnwrapSol": True,
"quoteResponse": quoteResponse
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
url = "https://quote-api.jup.ag/v6/swap"
response = requests.post(url, headers=headers, data=payload)
swapTransaction = response.json()
swap_transaction = swapTransaction["swapTransaction"]
raw_tx = VersionedTransaction.from_bytes(b64decode(swap_transaction))
signature = key_pair.sign_message(to_bytes_versioned(raw_tx.message))
signed_tx = VersionedTransaction.populate(raw_tx.message, [signature])
trx = client.send_transaction(
signed_tx,
opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed),
)
I followed the doc https://station.jup.ag/docs/apis/swap-api
But when I execute I have an error:
RPCException: SendTransactionPreflightFailureMessage { message:
"Transaction simulation failed: Error processing Instruction 3: custom
program error: 0x1", data:
RpcSimulateTransactionResult(RpcSimulateTransactionResult { err:
Some(InstructionError(3, Custom(1))), logs: Some(["Program
ComputeBudget111111111111111111111111111111 invoke [1]", "Program
ComputeBudget111111111111111111111111111111 success", "Program
ComputeBudget111111111111111111111111111111 invoke [1]", "Program
ComputeBudget111111111111111111111111111111 success", "Program
ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", "Program
log: CreateIdempotent", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log:
Instruction: GetAccountDataSize", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 1392795
compute units", "Program return:
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", "Program
11111111111111111111111111111111 invoke [2]", "Program
11111111111111111111111111111111 success", "Program log: Initialize
the associated token account", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log:
Instruction: InitializeImmutableOwner", "Program log: Please upgrade
to SPL Token 2022 for immutable owner support", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 1386208
compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
success", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke
[2]", "Program log: Instruction: InitializeAccount3", "Program
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3158 of 1382326
compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
success", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL
consumed 20815 of 1399700 compute units", "Program
ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success", "Program
11111111111111111111111111111111 invoke [1]", "Transfer: insufficient
lamports 382911515, need 400000000", "Program
11111111111111111111111111111111 failed: custom program error: 0x1"]),
accounts: None, units_consumed: Some(21115), return_data: None }) }
I see that I want to swap 0.4 SOL, and it seems that I am only sending 0.382911515. But how can I solve it as my input is already 0.4 SOL.
Thanks for your help!