Skip to content

Commit

Permalink
feat(createTransaction.ts): import VersionedTransaction and deseriali…
Browse files Browse the repository at this point in the history
…ze transaction to extract instructions for better transaction handling

fix(loadTransaction.ts): add console log for debugging purposes to indicate non-legacy transaction handling
chore(runTransaction.ts): remove runTransaction utility as it is no longer needed
feat(swap.ts): add isLegacy flag to newParams and log transaction instructions before sending for improved debugging
fix(package.json): change solana-send-transaction dependency to workspace version for better compatibility in monorepo setup
  • Loading branch information
javeoff committed Sep 28, 2024
1 parent bd5cbfe commit 2905bac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
8 changes: 8 additions & 0 deletions lib/utils/createTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VersionedTransaction } from "@solana/web3.js";
import { NetworkName } from "../types/NetworkName.js";
import { ENDPOINT } from "./constants.js";
import { loadTransaction } from "./loadTransaction.js";
Expand Down Expand Up @@ -50,6 +51,13 @@ export const createTransaction = async (params: CreateTransactionParams) => {
if (!('txn' in data)) {
throw new Error('Failed to create transaction: no txn found in response');
}
const txn = data.txn;
const transaction = VersionedTransaction.deserialize(
Buffer.from(txn, "base64"),
);
const instructions = (transaction.message as { instructions: unknown[] })
.instructions;
console.log(instructions);

return loadTransaction({ txn: data.txn, ...params });
}
1 change: 1 addition & 0 deletions lib/utils/loadTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const loadTransaction = <IsLegacy, Response = IsLegacy extends true ? Tra
return Transaction.from(Buffer.from(txn, "base64")) as Response;
}

console.log('nolegacy')
return VersionedTransaction.deserialize(
Buffer.from(txn, "base64"),
) as Response;
Expand Down
26 changes: 0 additions & 26 deletions lib/utils/runTransaction.ts

This file was deleted.

4 changes: 3 additions & 1 deletion lib/utils/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export const swap = async ({ wallet, connection: paramsConnection, ...params }:
const newParams = {
...params,
walletAddress,
isLegacy: false,
}
const transaction = await createTransaction(newParams as CreateTransactionParams);
const connection = paramsConnection || new Connection(process.env.CONNECTION_URL!, {
wsEndpoint: process.env.WS_CONNECTION_URL!,
});
transaction.sign([wallet]);
const txid = await sendTransaction(transaction, {
console.log((transaction.message as any).instructions)
const txid = await sendTransaction(transaction.serialize(), {
connection,
checkBlockHeight: false,
speed: 'fast',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@solana/web3.js": "1.93.1",
"@cryptoscan/solana-send-transaction": "latest"
"@cryptoscan/solana-send-transaction": "workspace:latest"
},
"devDependencies": {
"@semantic-release/commit-analyzer": "^13.0.0",
Expand Down

0 comments on commit 2905bac

Please sign in to comment.