4.5.0 • Published 9 days ago

solana-transactions-executor v4.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

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
4.5.0

9 days ago

4.4.0

18 days ago

4.2.0

26 days ago

4.3.0

26 days ago

4.1.0

27 days ago

4.0.0

1 month ago

4.0.0-beta.0

1 month ago

3.0.0-beta.20

1 month ago

3.0.0-beta.21

1 month ago

3.0.0-beta.19

1 month ago

3.0.0

1 month ago

3.0.0-beta.10

1 month ago

3.0.0-beta.11

1 month ago

3.0.0-beta.12

1 month ago

3.0.0-beta.13

1 month ago

3.0.0-beta.14

1 month ago

3.0.0-beta.15

1 month ago

3.0.0-beta.16

1 month ago

3.0.0-beta.17

1 month ago

3.0.0-beta.18

1 month ago

3.0.0-beta.1

1 month ago

3.0.0-beta.3

1 month ago

3.0.0-beta.2

1 month ago

3.0.0-beta.5

1 month ago

3.0.0-beta.4

1 month ago

3.0.0-beta.7

1 month ago

3.0.0-beta.6

1 month ago

3.0.0-beta.9

1 month ago

3.0.0-beta.8

1 month ago

2.3.0-beta.0

2 months ago

2.3.0-beta.1

2 months ago

2.2.5

2 months ago

2.2.6

2 months ago

2.2.1

2 months ago

2.1.2

2 months ago

2.2.0

2 months ago

2.2.3

2 months ago

2.1.4

2 months ago

2.2.2

2 months ago

2.1.3

2 months ago

2.1.6

2 months ago

2.2.4

2 months ago

2.1.5

2 months ago

2.1.7

2 months ago

2.1.1

2 months ago

1.2.2

2 months ago

1.2.1

2 months ago

2.1.0

2 months ago

2.0.1

2 months ago

2.0.0

2 months ago

1.2.0

2 months ago

1.7.1-beta.0

2 months ago

1.7.0

2 months ago

1.3.0

2 months ago

2.0.0-alpha.0

2 months ago

1.2.1-beta.0

2 months ago

1.2.1-beta.1

2 months ago

1.1.2

3 months ago

1.1.0

5 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago