MeshTxBuilder - All API Endpoints

Using MeshTxBuilder to build lower level transactions

For examples on how to build all possible transactions with MeshTxBuilder, please refer to the Craft Customized Transactions page.

Set pubkey input for transaction

txIn() is used to set the input for a transaction. amount and address are optional flags which can be used if you have supplied the fetcher instance (which enables blockchain indexing)

mesh
  .txIn(txHash: string, txIndex: number, amount?: Asset[], address?: string)

Set script input for transaction

There are 3 steps to utilise a script as part of the input for a transaction:

1. Notifying the current instance that we intend to spend a script input

2. Providing input information using .txIn()

3. Providing the necessary supplementary "spending" script information, which consists of:

(a) the script using one of

(i) Reference script.spendingTxInReference()
(ii) Supplying script.txInScript(scriptCbor: string)

(b) the redeemer using

`Note that the data provided can be the in type of "Mesh", "CBOR" or "JSON" (the JSON representation of PlutusData in DetailedSchema)`

.txInRedeemerValue(redeemer: Data | object | string, exUnits?: Budget, type: "Mesh" | "CBOR" | "JSON")

(c) the datum using one of

(i) Referencing inline datum.txInInlineDatumPresent()
(ii) Supplying datum .txInDatumValue(datum: Data | object | string, type?: "Mesh" | "CBOR" | "JSON")

Example of utilising a script for input:

mesh
  .spendingPlutusScriptV2()
  .txIn(txHash: string, txIndex: number, amount?: Asset[], address?: string)
  .txInInlineDatumPresent() // or .txInDatumValue(datum: Data | string | object)
  .txInRedeemerValue(redeemer: Data | object | string, exUnits?: Budget, type?: string)
  .spendingTxInReference(txHash: string, txIndex: number, spendingScriptHash?: string) // or supplying script

Set output for transaction

txOut() is used in its basic form as follows. You could provide empty array or only native token to amount: Asset[], in that case the minUTxO needed would be calculated automatically at complete.

mesh
  .txOut(address: string, amount: Asset[])

Attaching datum in output

You can attach datum to this transaction output by using either.txOutDatumHashValue() or .txOutInlineDatumValue()

mesh
  .txOut(address: string, amount: Asset[])
  .txOutDatumHashValue(datum: Data | object | string, type?: type: "Mesh" | "CBOR" | "JSON") 
    // or .txOutInlineDatumValue(datum: Data | object | string, type?: "Mesh" | "CBOR" | "JSON")

Attaching script in output for referencing

You can attach a reference script to the output using.txOutReferenceScript()

mesh
  .txOut(address: string, amount: Asset[])
  .txOutReferenceScript(scriptCbor: string)

Set read-only reference input

Use .readOnlyTxInReference() to specify a read-only reference input:

mesh
  .readOnlyTxInReference(txHash: string, txIndex: number)

Mint 'native script' token

When minting tokens using a 'native script' as input, there are 2 steps:

1. Providing the minting value (quantity, policy and name) using .mint()

2. Providing the script source using.mintingScript()

mesh
  .mint(quantity: string, policy: string, name: string)
  .mintingScript(scriptCbor: string)

Mint 'Plutus script' token

When minting tokens with a Plutus script as input, there are 3 steps:

1. Notifying the current instance that we are minting using a Plutus Script

2. Providing minting value (quantity, policy, name) with .mint()

3. Providing minting information, which consists of:

(a) the script source, supplied by either

(i) providing a Reference script with.mintTxInReference() or
(ii) Supplying script source (cbor string) directly with.mintingScript()

(b) the redeemer source with

`Note that the data provided can be the in type of "Mesh", "CBOR" or "JSON" (the JSON representation of PlutusData in DetailedSchema)`

.mintRedeemerValue()

Example of minting a token using a Plutus script:

mesh
  .mintPlutusScriptV2()
  .mint(quantity: string, policy: string, name: string)
  .mintTxInReference(txHash: string, txIndex: number) // or .mintingScript(scriptCbor: string)
  .mintRedeemerValue(redeemer: Data | object | string, exUnits?: Budget, type?: "Mesh" | "CBOR" | "JSON")

Set required signer

Use .requiredSignerHash() to set a required signer for the transaction:

mesh
  .requiredSignerHash(pubKeyHash: string)

Set collateral UTxO

Use .txInCollateral() to set the collateral UTxO for the transaction. Just as with .txIn(), you can optionally provide the amount and address information:

mesh
  .txInCollateral(txHash: string, txIndex: number, amount?: Asset[], address?: string)

Set change address

Use changeAddress() to set the change address:

mesh
  .changeAddress(address: string)

Set the transaction validity interval

Use .invalidBefore() to set the transaction validity interval to be valid only after the specified slot:

mesh
  .invalidBefore(slot: number)

Use .invalidHereafter() to set the transaction validity interval to be valid only before the specified slot:

mesh
  .invalidHereafter(slot: number)

Add metadata

Use .metadataValue() to add metadata to the transaction:

mesh
  .metadataValue(tag: string, metadata: object)

Register Stake Certificate

Use .registerStakeCertificate() to register a stake certificate:

mesh
  .registerStakeCertificate(stakeKeyHash: string)

Deregister Stake Certificate

Use .deregisterStakeCertificate() to deregister a stake certificate:

mesh
  .deregisterStakeCertificate(stakeKeyHash: string)

Delegate Stake to a Pool

Use .delegateStakeCertificate() to delegate a stake to a pool:

mesh
  .delegateStakeCertificate(stakeKeyHash: string, poolId: string)

Register Pool Certificate

Use .registerPoolCertificate() to register a pool certificate:

mesh
  .registerPoolCertificate(poolParams: PoolParams)

Retire Pool Certificate

Use .retirePoolCertificate() to retire a pool certificate:

mesh
  .retirePoolCertificate(poolId: string, epoch: number)

Sign with signing key

Use .signingKey() to sign the transaction with the private key (provided in cbor hex format):

mesh
  .signingKey(skeyHex: string)

Complete

In the Mesh lower-level API, the transaction building process is concluded by using either the .complete() or .completeSync() method, at which point the MeshTxBuilder instance analyses and completes the serialization of the built transaction so that (if it is valid) it is ready to be submitted to the blockchain.

You can also directly supply the optional parameter in MeshTxBuilderBody to build the transaction using the supplied object.

Use .complete() (an async method) to complete the transaction building process:

await mesh
  .complete(customizedTx?: MeshTxBuilderBody)

Use .completeSync() to complete the transaction building process without indexing the blockchain:

mesh
  .completeSync(customizedTx?: MeshTxBuilderBody)

Use .completeSigning() to add private key signing to the witness set process without indexing the blockchain:

const signedTx = mesh
  .completeSigning()