Learn how script oracles work
Submit CreateScriptOracle message to create the calculator
🔮 ORACLE CREATION: Submit a CreateScriptOracle message with a JSON Logic script program. This oracle is stateless (initialState: null) and supports add, subtract, multiply, and divide methods. The script uses nested if statements to route to the correct operation based on the "method" parameter.
{
"cid": "oracle-uuid-here",
"scriptProgram": {
"if": [
{
"==": [
{
"var": "method"
},
"add"
]
},
{
"+": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"subtract"
]
},
{
"-": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"multiply"
]
},
{
"*": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"divide"
]
},
{
"/": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"error": "Unknown method"
}
]
}
]
}
]
}
]
},
"initialState": null,
"accessControl": {
"Public": {}
}
}null (stateless oracle)
The calculator oracle uses nested if statements in JSON Logic to route method calls to the appropriate arithmetic operation:
{
"if": [
{
"==": [
{
"var": "method"
},
"add"
]
},
{
"+": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"subtract"
]
},
{
"-": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"multiply"
]
},
{
"*": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"if": [
{
"==": [
{
"var": "method"
},
"divide"
]
},
{
"/": [
{
"var": "args.a"
},
{
"var": "args.b"
}
]
},
{
"error": "Unknown method"
}
]
}
]
}
]
}
]
}Oracles are separate entities created with CreateScriptOracle and invoked with InvokeScriptOracle
Oracle programs use JSON Logic with if statements to route method calls and perform computations
Oracles can be stateless (initialState: null) for pure computations like arithmetic
State machines can call oracles using _oracleCall in their effects for external computations