pumpdotfun-repumped-sdk
Version:
Pumpfun SDK — create, buy, sell tokens with support for Jito bundles and multiple relayer integrations. Rebuilt and fixed pumpdotfun-sdk.
79 lines (76 loc) • 2.94 kB
JavaScript
import { SendTransactionError, TransactionMessage, VersionedTransaction, Transaction, ComputeBudgetProgram } from '@solana/web3.js';
import { DEFAULT_COMMITMENT, DEFAULT_FINALITY } from './pumpFun.consts.mjs';
async function sendTx(connection, tx, payer, signers, priorityFees, commitment = DEFAULT_COMMITMENT, finality = DEFAULT_FINALITY) {
let versionedTx = await buildSignedTx(priorityFees, tx, connection, payer, commitment, signers);
try {
const sig = await connection.sendTransaction(versionedTx, {
skipPreflight: false,
});
console.log("sig:", `https://solscan.io/tx/${sig}`);
let txResult = await getTxDetails(connection, sig, commitment, finality);
if (!txResult) {
return {
success: false,
error: "Transaction failed",
};
}
return {
success: true,
signature: sig,
results: txResult,
};
}
catch (e) {
if (e instanceof SendTransactionError) {
let ste = e;
console.log("SendTransactionError" + ste.logs);
}
else {
console.error(e);
}
return {
error: e,
success: false,
};
}
}
const buildVersionedTx = async (connection, payer, tx, commitment = DEFAULT_COMMITMENT) => {
const blockHash = (await connection.getLatestBlockhash(commitment)).blockhash;
let messageV0 = new TransactionMessage({
payerKey: payer,
recentBlockhash: blockHash,
instructions: tx.instructions,
}).compileToV0Message();
return new VersionedTransaction(messageV0);
};
const getTxDetails = async (connection, sig, commitment = DEFAULT_COMMITMENT, finality = DEFAULT_FINALITY) => {
const latestBlockHash = await connection.getLatestBlockhash();
await connection.confirmTransaction({
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
signature: sig,
}, commitment);
return connection.getTransaction(sig, {
maxSupportedTransactionVersion: 0,
commitment: finality,
});
};
async function buildSignedTx(priorityFees, tx, connection, payer, commitment, signers) {
let newTx = new Transaction();
if (priorityFees) {
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: priorityFees.unitLimit,
});
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: priorityFees.unitPrice,
});
newTx.add(modifyComputeUnits);
newTx.add(addPriorityFee);
}
newTx.add(tx);
let versionedTx = await buildVersionedTx(connection, payer, newTx, commitment);
versionedTx.sign(signers);
return versionedTx;
}
export { buildSignedTx, buildVersionedTx, getTxDetails, sendTx };
//# sourceMappingURL=tx.mjs.map