MeshTxBuilder - All APIs
Using MeshTxBuilder for building 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
Use txIn()
to set the input for transaction. amount
and address
are optional flags if you have the fetcher
instance supplied, where blockchain indexing would be performed on
mesh .txIn(txHash: string, txIndex: number, amount?: Asset[], address?: string)
Set script input for transaction
When spending a script input, there are 3 steps
1. Notifying the instance currently we would spend a script input
2. Providing input information by .txIn()
3. Providing spending information for
(a) the script source by
(i) Reference script.spendingTxInReference()
(ii) Supplying script.txInScript(scriptCbor: string)
(b) the redeemer source by
.txInRedeemerValue()
(c) the datum source by
(i) Referencing inline datum.txInInlineDatumPresent()
(ii) Supplying datum .txInDatumValue(datum: Data)
A complete example below:
mesh .spendingPlutusScriptV2() .txIn(txHash: string, txIndex: number, amount?: Asset[], address?: string) .txInInlineDatumPresent() // or .txInDatumValue(datum: Data) .txInRedeemerValue(redeemer: Redeemer, exUnits?: Budget) .spendingTxInReference(txHash: string, txIndex: number, spendingScriptHash?: string) // or supplying script
Set output for transaction
Use txOut()
to set the input datum for transaction:
mesh .txOut(address: string, amount: Asset[])
Attaching datum in output
You could attach datum with the output by.txOutDatumHashValue()
or .txOutInlineDatumValue()
mesh .txOut(address: string, amount: Asset[]) .txOutDatumHashValue(datum: Data) // or .txOutInlineDatumValue(datum: Data)
Attaching script in output for referencing
You could attach script the output by.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 a native script token input, there are 2 steps
1. Providing minting value by .mint()
2. Providing the script source by supplying script using.mintingScript()
mesh .mint(quantity: number, policy: string, name: string) .mintingScript(scriptCbor: string)
Mint Plutus script token
When minting a Plutus token input, there are 3 steps
1. Notifying the instance currently we would minting a Plutus token
2. Providing minting value by .mint()
3. Providing minting information for
(a) the script source by
(i) Reference script.mintTxInReference()
(ii) Supplying script.mintingScript()
(b) the redeemer source by
.mintRedeemerValue()
A complete example below:
mesh .mintPlutusScriptV2() .mint(quantity: number, policy: string, name: string) .mintTxInReference(txHash: string, txIndex: number) // or .mintingScript(scriptCbor: string) .mintRedeemerValue(redeemer: Redeemer, exUnits?: Budget)
Set required signer
Use .requiredSignerHash()
to set the required signer of the transaction:
mesh .requiredSignerHash(pubKeyHash: string)
Set collateral UTxO
Use .txInCollateral()
to set the collateral UTxO for the transaction. Similar with .txIn()
, you could optionally provide the amount and address information of UTxO:
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 valid interval to be valid only after the slot:
mesh .invalidBefore(slot: number)
Use .invalidHereafter()
to set the transaction valid interval to be valid only before the slot:
mesh .invalidHereafter(slot: number)
Add metadata
Use .metadataValue()
to add metadata to the transaction:
mesh .metadataValue(tag: string, metadata: object)
Sign with signing key
Use .signingKey()
to sign the transaction with the private key in cbor hex format:
mesh .signingKey(skeyHex: string)
Complete
In the Mesh lower level APIs, transaction building process is finished by the .complete()
or .completeSync()
method, where the MeshTxBuilder
instance would look into your transaction building process so far and serialize the transaction ready to be submitted to the blockchain.
You could also directly supplying the optional parameter in MeshTxBuilderBody
to build the transaction with the object supplied.
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 blockchain:
mesh .completeSync(customizedTx?: MeshTxBuilderBody)
Use .completeSigning()
to add private key signing to the witness set process without indexing blockchain:
const signedTx = mesh .completeSigning()
Schemas
All the schemas utilizing in the Mesh lower level APIs could be found here.
MeshTxBuilderBody = { inputs: TxIn[] outputs: Output[]; collaterals: PubKeyTxIn[]; requiredSignatures: string[]; referenceInputs: RefTxIn[]; mints: MintItem[]; changeAddress: string; metadata: Metadata[]; validityRange: ValidityRange; signingKey: string[]; }
Detail types in constructing the MeshTxBuilderBody can be found here
TxIn
TxIn = PubKeyTxIn | ScriptTxIn;
PubKeyTxIn
PubKeyTxIn = { type: 'PubKey'; txIn: { txHash: string; txIndex: number; amount?: Asset[]; address?: string; } }
ScriptTxIn
PubKeyTxIn = { type: 'Script'; txIn: { txHash: string; txIndex: number; amount?: Asset[]; address?: string; } scriptTxIn: { scriptSource?: { txHash: string; txIndex: number; spendingScriptHash?: string; }; datumSource?: | { type: 'Provided'; data: Data; } | { type: 'Inline'; txHash: string; txIndex: number; }; redeemer?: { data: Data; exUnits: Budget; }; } }
RefTxIn
RefTxIn = { txHash: string; txIndex: number; }
Output
Output = { address: string; amount: Asset[]; datum?: { type: 'Hash' | 'Inline'; data: Data; }; referenceScript?: string; }
MintItem
MintItem = { type: 'Plutus' | 'Native'; policyId: string; assetName: string; amount: number; redeemer?: Redeemer; scriptSource?: | { type: 'Provided'; cbor: string; } | { type: 'Reference Script'; txHash: string; txIndex: number; }; }
Redeemer
Redeemer = { data: Data; exUnits: Budget; }
Metadata
Metadata = { tag: string; metadata: object; }
ValidityRange
ValidityRange = { invalidBefore?: number; invalidHereafter?: number; }
Asset
Asset = { unit: string; quantity: string; }
Data
Data = string | number | Array<Data> | Map<Data, Data> | { alternative: number; fields: Array<Data>; }