var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=3&rec=1&url=https://docs.warp.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Variables

Variables are placeholders for arbitrary data that can be inserted into Warp jobs and conditions. To make creating jobs easier, variables can be specified and input into job or query templates. After creating variables, you can add them to messages using their reference value in the form of $warp.variable.variable-name. You can use variables with templates to create complex reusable jobs. Variables created in the Warp app are stored in your browser and are not written to the blockchain until they are inserted into templates.

VariableKind

The following are the different variable input types that can be used.

variable.rs
Copy

_10
pub enum VariableKind {
_10
String,
_10
Uint,
_10
Int,
_10
Decimal,
_10
Timestamp,
_10
Bool,
_10
Amount,
_10
Asset,
_10
}

Static variables

Static variables are the simplest form of variable and are created with a value. Static variable values can be updated in loops using an UpdateFn.

variable.rs
Copy

_7
#[cw_serde]
_7
pub struct StaticVariable {
_7
pub kind: VariableKind,
_7
pub name: String,
_7
pub value: String,
_7
pub update_fn: Option<UpdateFn>,
_7
}

Query variables

Query variables allow you to select a value from the response of a specified query. Queries require a query message and a selector, which is used to select the correct portion of the query response. When looping, query variables can be updated or specified to be reinitialized.

variable.rs
Copy

_13
pub struct QueryVariable {
_13
pub kind: VariableKind,
_13
pub name: String,
_13
pub init_fn: QueryExpr,
_13
pub reinitialize: bool,
_13
pub value: Option<String>, //none if uninitialized
_13
pub update_fn: Option<UpdateFn>,
_13
}
_13
_13
pub struct QueryExpr {
_13
pub selector: String,
_13
pub query: QueryRequest<String>,
_13
}

External Variables

External variables are fetched from external sources such as APIs. They require an external reference input, which includes a URL, a method (Get, Post, Push, Pass, Delete), a header, a body, and a JSON selector. External variables can be updated or specified to be reinitialized.

variable.rs
Copy

_17
pub struct ExternalVariable {
_17
pub kind: VariableKind,
_17
pub name: String,
_17
pub init_fn: ExternalExpr,
_17
pub reinitialize: bool,
_17
pub value: Option<String>, //none if uninitialized
_17
pub update_fn: Option<UpdateFn>,
_17
}
_17
_17
_17
pub struct ExternalExpr {
_17
pub url: String,
_17
pub method: Option<Method>,
_17
pub headers: Option<Vec<String>>,
_17
pub body: Option<String>,
_17
pub selector: String,
_17
}

Update functions and loops

Variables can be updated using an update function, which can change the value of the variable upon the success or failure of a job. By specifying whether a variable should update after completion, jobs can be looped. You can specify how a value should be updated upon success or upon failure, and you can use an update function to update the value. Update functions can include a NumValue and an operator to update the value. A NumValue can also reference an expression or variable such as a query, allowing for further looping and update capability.

variable.rs
Copy

_15
_15
pub enum UpdateFnValue {
_15
Uint(NumValue<Uint256, NumExprOp, IntFnOp>),
_15
Int(NumValue<i128, NumExprOp, IntFnOp>),
_15
Decimal(NumValue<Decimal256, NumExprOp, DecimalFnOp>),
_15
Timestamp(NumValue<i128, NumExprOp, IntFnOp>),
_15
BlockHeight(NumValue<i128, NumExprOp, IntFnOp>),
_15
Bool(String),
_15
}
_15
_15
#[cw_serde]
_15
pub struct UpdateFn {
_15
pub on_success: Option<UpdateFnValue>,
_15
pub on_error: Option<UpdateFnValue>,
_15
}

Reinitialize

Expression and Query variables contain a reinitialize boolean, which specifies whether the query or external variable should be fetched again. If this boolean is set to true, the job will be run again after completion (on success or failure) and the data will be fetched again upon each subsequent job. Vasssriables cannot be updated using an UpdateFn if the reinitialize boolean is true.