Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Left() {
signature += ` submitter?: ISubmitter;\n`;
signature += ` evaluator?: IEvaluator;\n`;
signature += ` serializer?: IMeshTxSerializer;\n`;
signature += ` selector?: IInputSelector;\n`;
signature += ` isHydra?: boolean;\n`;
signature += ` params?: Partial<Protocol>;\n`;
signature += ` verbose?: boolean;\n`;
Expand All @@ -47,7 +48,7 @@ function Left() {
<Codeblock data={signature} />

<p>
There are 6 optional fields to pass in to initialized the lower level
There are 7 optional fields to pass in to initialize the lower level
APIs instance:
</p>

Expand All @@ -72,6 +73,12 @@ function Left() {
<code>evaluator</code>: It would perform redeemer execution unit
optimization, returning error message in case of invalid transaction.
</li>
<li>
<code>selector</code>: The coin selection strategy selector. Defaults to{" "}
<code>CardanoSdkInputSelector</code> which uses Cardano SDK's round-robin random improve algorithm.
You can also use <code>LargestFirstInputSelector</code> for largest-first selection algorithm,
or implement a custom selector by implementing the <code>IInputSelector</code> interface.
</li>
<li>
<code>isHydra</code>: Use another set of default protocol parameters
for building transactions.
Expand Down
56 changes: 56 additions & 0 deletions packages/mesh-transaction/src/mesh-tx-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ import {
} from "./coin-selection/coin-selection-interface";
import { MeshTxBuilderCore } from "./tx-builder-core";

/**
* Options for initializing a MeshTxBuilder instance.
*
* @param fetcher - Optional fetcher for blockchain data. Used to query missing transaction information.
* @param submitter - Optional submitter for transactions. Used to submit transactions directly from the builder instance.
* @param evaluator - Optional evaluator for redeemer execution unit optimization. Returns error messages for invalid transactions.
* @param serializer - Optional serializer for transaction serialization. Defaults to CardanoSDKSerializer.
* @param selector - Optional coin selection strategy selector. Defaults to CardanoSdkInputSelector.
* Available built-in selectors:
* - CardanoSdkInputSelector: Default selector using Cardano SDK's round-robin random improve algorithm
* - LargestFirstInputSelector: Largest-first selection algorithm
* Custom selectors can be created by implementing the IInputSelector interface.
* @param isHydra - Optional flag to use Hydra-specific protocol parameters (all fees set to 0).
* @param params - Optional partial protocol parameters to override defaults.
* @param verbose - Optional flag to enable verbose logging for transaction building.
*/
export interface MeshTxBuilderOptions {
fetcher?: IFetcher;
submitter?: ISubmitter;
Expand All @@ -58,6 +74,30 @@ export interface MeshTxBuilderOptions {
verbose?: boolean;
}

/**
* MeshTxBuilder provides a comprehensive API for building Cardano transactions.
* It supports various transaction types including payments, token minting, smart contract interactions, and more.
*
* @example
* ```javascript
* import { MeshTxBuilder, BlockfrostProvider, LargestFirstInputSelector } from '@meshsdk/core';
*
* const provider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
*
* // Initialize with default selector
* const txBuilder = new MeshTxBuilder({
* fetcher: provider,
* submitter: provider,
* verbose: true,
* });
*
* // Initialize with custom selector (largest-first algorithm)
* const txBuilderWithCustomSelector = new MeshTxBuilder({
* fetcher: provider,
* selector: new LargestFirstInputSelector(),
* });
* ```
*/
export class MeshTxBuilder extends MeshTxBuilderCore {
serializer: IMeshTxSerializer;
selector: IInputSelector;
Expand All @@ -70,6 +110,22 @@ export class MeshTxBuilder extends MeshTxBuilderCore {
protected queriedUTxOs: { [x: string]: UTxO[] } = {};
protected utxosWithRefScripts: UTxO[] = [];

/**
* Creates a new MeshTxBuilder instance.
*
* @param options - Configuration options for the transaction builder
* @param options.serializer - Optional serializer instance. Defaults to CardanoSDKSerializer.
* @param options.selector - Optional coin selection strategy. Defaults to CardanoSdkInputSelector.
* Use this to customize how UTxOs are selected for transactions.
* Built-in options: CardanoSdkInputSelector, LargestFirstInputSelector.
* Custom selectors must implement the IInputSelector interface.
* @param options.fetcher - Optional fetcher for blockchain data queries.
* @param options.submitter - Optional submitter for transaction submission.
* @param options.evaluator - Optional evaluator for redeemer execution unit optimization.
* @param options.params - Optional protocol parameters to override defaults.
* @param options.isHydra - If true, uses Hydra-specific protocol parameters (all fees set to 0).
* @param options.verbose - If true, enables verbose logging during transaction building.
*/
constructor({
serializer,
selector,
Expand Down
39 changes: 38 additions & 1 deletion packages/mesh-wallet/src/mesh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,56 @@ export type CreateMeshWalletOptions = {
* - mnemonic: A list of 24 words
* - address: A bech32 address that can be used to create a read-only wallet, generally starts with `addr` or `addr_test1`
*
* @param options.networkId - The network ID (1 for mainnet, 0 for testnet)
* @param options.fetcher - Optional fetcher for blockchain data
* @param options.submitter - Optional submitter for transactions
* @param options.key - The key configuration (one of: root, cli, mnemonic, bip32Bytes, or address)
* @param options.accountIndex - Optional account index (default: 0)
* @param options.keyIndex - Optional key index (default: 0)
* @param options.accountType - Optional account type: "payment" (default), "stake", or "drep".
* Determines which key is used for signing transactions:
* - "payment": Uses the payment key (default behavior)
* - "stake": Uses the stake key for staking-related transactions
* - "drep": Uses the DRep key for delegation representative transactions
*
* ```javascript
* import { MeshWallet, BlockfrostProvider } from '@meshsdk/core';
*
* const provider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
*
* // Create wallet with default payment account
* const wallet = new MeshWallet({
* networkId: 0,
* fetcher: provider,
* submitter: provider,
* key: {
* type: 'mnemonic',
* words: ["solution","solution","solution","solution","solution",","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
* words: ["solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
* },
* });
*
* // Create wallet with stake account type for staking transactions
* const stakeWallet = new MeshWallet({
* networkId: 0,
* fetcher: provider,
* submitter: provider,
* key: {
* type: 'mnemonic',
* words: ["solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
* },
* accountType: 'stake',
* });
*
* // Create wallet with drep account type for delegation representative transactions
* const drepWallet = new MeshWallet({
* networkId: 0,
* fetcher: provider,
* submitter: provider,
* key: {
* type: 'mnemonic',
* words: ["solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
* },
* accountType: 'drep',
* });
* ```
*
Expand Down