Skip to main content

Lit Action Conditions

You can create a Lit Action Condition to grant access whenever a given Lit Action meets the conditions you set. Lit Actions are JS code that can be executed on the Lit Protocol network. You can use Lit Actions to create custom access control conditions.

Example: Lit Action Must Return True

Suppose you wanted to make a Lit Action that returns true if the forecast temperature is below 40 degrees. You could use this to create a document that can only be decrypted when it's cold out.

This would be your Lit Action code, and is where you choose your conditions. You can talk to any API here:

const go = async (maxTemp) => {
const url = ",71/forecast";
try {
const response = await fetch(url).then((res) => res.json());
const nearestForecast =[0];
const temp = nearestForecast.temperature;
return temp < parseInt(maxTemp);
} catch (e) {
return false;

Save the above code to IPFS.

In this example, the Lit Action is on IPFS with the CID QmcgbVu2sJSPpTeFhBd174FnmYmoVYvUFJeDkS7eYtwoFY. The below condition will run the go() function of the Lit Action, and check if the return value is true. It will pass a parameter of 40 to the go() function. Note that all parameters must be strings so you must use parseInt() to convert the string to a number to check it against the forecast temperature.

var accessControlConditions = [
contractAddress: "ipfs://QmcgbVu2sJSPpTeFhBd174FnmYmoVYvUFJeDkS7eYtwoFY",
standardContractType: "LitAction",
chain: "ethereum",
method: "go",
parameters: ["40"],
returnValueTest: {
comparator: "=",
value: "true",

You can see a full working example of this here:

Return Value Options

Your JS function can return any string (not just true or false), and you can compare it against any string in your returnValueTest. Note that only strings are supported here, so you should stick to the comparator options that make sense with strings. These are below:

  • =
  • !=
  • contains
  • !contains

Not finding the answer you're looking for? Share your feedback on these docs by creating an issue in our GitHub Issues and Reports repository or get support by visiting our Support page.