npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solana-transactions-executor

v6.0.0

Published

A small solution to operate solana transactions: create, sign, send, chunk, support ledger etc.

Downloads

290

Readme

IMPORTANT! The documentation is not up to date. We use this toolkit for banx.gg. I'm contributing very active and don't have time to update the documentation. I hope you understand. It's better to look into the code itself.

solana-transactions-executor

A small solution to operate solana transactions: create, sign, send, chunk, support ledger etc.

yarn add solana-transactions-executor # npm install solana-transactions-executor or pnpm add solana-transactions-executor

This package is designed to be used on the frontend of your React web3 application to simplify complex transactional interactions. It assumes that you are already using @solana/web3.js and @solana/wallet-adapter-react

Usage example

const { connection } = useConnection()
const wallet = useWallet()
const isLedger = false

const txnsResults = await new TxnExecutor(
  makeBorrowAction,
  { wallet, connection },
  { signAllChunks: isLedger ? 1 : 40, rejectQueueOnFirstPfError: false },
)
  .addTxnParams(txnParams)
  .on('pfSuccessEach', (results) => {
    //? Some action if the transction is successfull. Triggered after each successfull preflight
  })
  .on('pfSuccessAll', (results) => {
    //? Some action if all transactions are successfull. Triggers after all successfull preflights
  })
  .on('pfError', (error) => {
    //? Some action on a failed transaction. Triggers for each transaction error
  })
  .execute()

const makeBorrowAction: MakeBorrowAction = async (ixnParams, walletAndConnection) => {
  const { instructions, signers, additionalResult } = await getIxnsAndSignersByBorrowType({
    ixnParams,
    type: borrowType,
    walletAndConnection,
  })

  return {
    instructions,
    signers,
    additionalResult,
    lookupTables: [new web3.PublicKey(LOOKUP_TABLE)],
  }
}

Execution process

  • Create new instance of TxnExecutor
  • Add params for your transaction(s)
  • Add event handlers if needed
  • Execute transaction(s)

Contructor params:

  • makeActionFn: MakeActionFn<TParams, TResult> - function that accepts params <TParams> to build your transaction results <TResult>
  • walletAndConnection: WalletAndConnection - Wallet and Connection objects: {wallet, connection}
  • options?: Partial<ExecutorOptions> - Additional contructor options

Additional contructor options:

export type ExecutorOptions = {
  commitment: Commitment
  signAllChunks: number //? Specify how many trasactions you want to sign per chunk using signAllTransactions method (use 1 for ledger because it doesn't support signAllTransactions method)
  skipPreflight: boolean //? if you want to skipPreflight on sendTransaction
  preflightCommitment: Commitment
  rejectQueueOnFirstPfError: boolean //? Stop sending other txns after first preflight error. Mostly relevant for the ledger
  chunkCallOfActionFn: boolean //? If true -- call makeActionFn for each chunk (between wallet approve). If false -- call makeActionFn for all txnsParams at once
}

Transaction(s) params

To pass parameters to MakeActionFn<TParams, TResult> to create a transaction, use the addTxnParam or addTxnParams methods. You may chain addTxnParam calls or pass txn params via array into addTxnParams. The number of sent transactions will depend on the number of parameters TParams.

Event hanlders

  • beforeFirstApprove: () => void - Triggers before first chunk approve
  • beforeApproveEveryChunk: () => void - Triggers after beforeFirstApprove and before each chunk approve
  • pfSuccessAll: (result: SendTxnsResult<TResult>) => void - Triggers if all chunks were successfully sent
  • pfSuccessSome: (result: SendTxnsResult<TResult>) => void - Triggers if at least one chunk was successfully sent
  • pfSuccessEach: (result: SendTxnsResult<TResult>) => void - Triggers after successfull send of each chunk
  • pfError: (error: TxnError) => void - Triggers on any error