Documentation / @cashconnect-js/templates-dev / helpers/instructions
Instructions
Defined in: packages/templates-dev/src/helpers/instructions.ts:11
Constructors
Constructor
new Instructions(): Instructions;Returns
Methods
transaction()
static transaction(txShape): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:12
Parameters
| Parameter | Type |
|---|---|
txShape | Partial<InstructionTransactionPayload> |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "transaction" | packages/core/dist/templates.d.ts:1145 |
payload | object | packages/core/dist/templates.d.ts:1147 |
payload.name | string | packages/core/dist/templates.d.ts:1148 |
payload.version | number | packages/core/dist/templates.d.ts:1149 |
payload.locktime | string | number | packages/core/dist/templates.d.ts:1150 |
payload.inputs | ( | "*" | { outpointTransactionHash: string; outpointIndex: string | number; sequenceNumber: string | number; $if?: string; unlockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; })[] | packages/core/dist/templates.d.ts:1151 |
payload.outputs | ( | "*" | { valueSatoshis: string | bigint; $if?: string; lockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; token?: { category: string | Uint8Array<ArrayBuffer>; amount?: string | bigint; nft?: { capability: "none" | "mutable" | "minting"; commitment: string; }; }; })[] | packages/core/dist/templates.d.ts:1161 |
payload.validate | boolean | packages/core/dist/templates.d.ts:1181 |
$if? | string | packages/core/dist/templates.d.ts:1146 |
consolidationTransaction()
static consolidationTransaction(
name,
valueSatoshis,
txShape?): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:28
Parameters
| Parameter | Type |
|---|---|
name | string |
valueSatoshis | string | bigint |
txShape? | Partial<{ name: string; version: number; locktime: string | number; inputs: ( | "*" | { outpointTransactionHash: string; outpointIndex: string | number; sequenceNumber: string | number; $if?: string; unlockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; })[]; outputs: ( | "*" | { valueSatoshis: string | bigint; $if?: string; lockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; token?: { category: string | Uint8Array<ArrayBuffer>; amount?: string | bigint; nft?: { capability: ... | ... | ...; commitment: string; }; }; })[]; validate: boolean; }> |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "transaction" | packages/core/dist/templates.d.ts:1145 |
payload | object | packages/core/dist/templates.d.ts:1147 |
payload.name | string | packages/core/dist/templates.d.ts:1148 |
payload.version | number | packages/core/dist/templates.d.ts:1149 |
payload.locktime | string | number | packages/core/dist/templates.d.ts:1150 |
payload.inputs | ( | "*" | { outpointTransactionHash: string; outpointIndex: string | number; sequenceNumber: string | number; $if?: string; unlockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; })[] | packages/core/dist/templates.d.ts:1151 |
payload.outputs | ( | "*" | { valueSatoshis: string | bigint; $if?: string; lockingBytecode?: | string | { script: string; resolve?: Record<string, string>; }; token?: { category: string | Uint8Array<ArrayBuffer>; amount?: string | bigint; nft?: { capability: "none" | "mutable" | "minting"; commitment: string; }; }; })[] | packages/core/dist/templates.d.ts:1161 |
payload.validate | boolean | packages/core/dist/templates.d.ts:1181 |
$if? | string | packages/core/dist/templates.d.ts:1146 |
resolve()
static resolve(fieldsToCashASM): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:51
Parameters
| Parameter | Type |
|---|---|
fieldsToCashASM | InstructionResolvePayload |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "resolve" | packages/core/dist/templates.d.ts:960 |
payload | z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodObject<{ script: z$1.ZodString; resolve: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>; }, z$1.core.$strip>]>> | packages/core/dist/templates.d.ts:961 |
createState()
static createState<T>(
prefix,
schema,
fields): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:74
Creates a new state by mapping fields to a prefixed namespace. All fields in the schema must be provided - use for initializing new state objects.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix for the state (e.g., 'match') |
schema | T | The state schema defining required fields |
fields | Record<keyof T, string> | Values for all fields in the schema |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "resolve" | packages/core/dist/templates.d.ts:960 |
payload | z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodObject<{ script: z$1.ZodString; resolve: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>; }, z$1.core.$strip>]>> | packages/core/dist/templates.d.ts:961 |
Example
Instructions.createState('match', MatchState, {
matchTxHash: expr`createMatchTxHash`,
matchAmount: expr`matchAmount`,
})forwardState()
static forwardState<T>(
prefix,
schema,
overrides?): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:96
Forwards all fields from a prefixed state, allowing selective overrides. Fields without overrides pass through unchanged.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix for the state (e.g., 'offerNo') |
schema | T | The state schema defining available fields |
overrides? | Partial<Record<keyof T, string>> | Optional field values to override instead of passing through |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "resolve" | packages/core/dist/templates.d.ts:960 |
payload | z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodObject<{ script: z$1.ZodString; resolve: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>; }, z$1.core.$strip>]>> | packages/core/dist/templates.d.ts:961 |
Example
Instructions.forwardState('offerNo', OfferState, {
offerTxHash: expr`createMatchTxHash`,
liquidityAmount: expr`noRemainingLiquidity`,
})copyState()
static copyState<T>(
fromPrefix,
toPrefix,
schema,
overrides?): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:122
Copies all fields from one prefixed state to another prefix, allowing selective overrides. Useful when transferring state between different namespaces (e.g., copying offer state to a new context).
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
fromPrefix | string | The source namespace prefix (e.g., 'offerYes') |
toPrefix | string | The destination namespace prefix (e.g., 'offer') |
schema | T | The state schema defining available fields |
overrides? | Partial<Record<keyof T, string>> | Optional field values to override instead of copying from source |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "resolve" | packages/core/dist/templates.d.ts:960 |
payload | z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodObject<{ script: z$1.ZodString; resolve: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>; }, z$1.core.$strip>]>> | packages/core/dist/templates.d.ts:961 |
Example
// Copy with selective overrides
Resolve.copyState('offerYes', 'offer', OfferState, {
offerTxHash: expr`newTxHash`,
})
// Result: { 'offer__offerTxHash': 'newTxHash', 'offer__field2': '<offerYes__field2>', ... }flattenState()
static flattenState<T>(prefix, schema): object;Defined in: packages/templates-dev/src/helpers/instructions.ts:144
Flattens a prefixed state into unprefixed keys. Use when you need to expose state fields without their prefix in the namespace.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix of the source state (e.g., 'stateB') |
schema | T | The state schema defining available fields |
Returns
object
| Name | Type | Defined in |
|---|---|---|
type | "resolve" | packages/core/dist/templates.d.ts:960 |
payload | z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodObject<{ script: z$1.ZodString; resolve: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>; }, z$1.core.$strip>]>> | packages/core/dist/templates.d.ts:961 |
Example
Instructions.flattenState('stateB', StateBSchema)
// Produces: { eventId: '<stateB__eventId>', ... }if()
static if<T>(condition, instruction): T & object;Defined in: packages/templates-dev/src/helpers/instructions.ts:151
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type |
|---|---|
condition | string |
instruction | T |
Returns
T & object
ifGroup()
static ifGroup<T>(condition, instructions): T & object[];Defined in: packages/templates-dev/src/helpers/instructions.ts:166
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type |
|---|---|
condition | string |
instructions | T[] |
Returns
T & object[]