A value node that differs based on a condition.
Attribute | Type | Description |
---|---|---|
kind |
"conditionalValueNode" |
The node discriminator. |
Attribute | Type | Description |
---|---|---|
condition |
AccountValueNode | ArgumentValueNode | ResolverValueNode |
The condition that must be met. If it is an argument or value node, the value attribute may be used to assert on a specific value. |
value |
ValueNode |
(Optional) If provided, the condition must be equal to this value. Otherwise, the condition must simply exist. |
ifTrue |
InstructionInputValueNode |
(Optional) The value to use if the condition is true. |
ifFalse |
InstructionInputValueNode |
(Optional) The value to use if the condition is false. |
Helper function that creates a ConditionalValueNode
object from an input object.
const node = conditionalValueNode({
condition: argumentValueNode('amount'),
value: numberValueNode(0),
ifTrue: accountValueNode('mint'),
ifFalse: programIdValueNode(),
});
instructionNode({
name: 'transfer',
accounts: [
instructionAccountNode({
name: 'source',
isSigner: false,
isWritable: true,
}),
instructionAccountNode({
name: 'destination',
isSigner: false,
isWritable: true,
isOptional: true,
defaultValue: conditionalValueNode({
condition: argumentValueNode('amount'),
value: numberValueNode(0),
ifTrue: accountValueNode('source'),
}),
}),
// ...
],
arguments: [
instructionArgumentNode({
name: 'amount',
type: numberTypeNode('u64'),
}),
],
});