Set Actions

Set Lit Action Code.

The setActions method let's you add custom, contract and fetch actions that are executed by the nodes on the Lit Network. These actions are only invoked if the conditions set in setConditions are met.

When invoking this method, you provide an array of actions that you want to set. The setActions returns the Lit Action code as a string that will be executed on the Lit Nodes and an unsignedTransactionDataObject that is only populated when instantiating ContractActions.

This is an asynchronous method, make sure to use await.

If undefined is passed to either of the gasLimit, maxPriorityFeePerGas or maxFeePerGas fields they will be calculated internally as the transaction is simulated. If you'd like more control over these fields please pass in correctly calculated values.

If you're transaction requires approval or funding of the PKP Wallet before it's broadcast, these values must be passed in manually. This is necessary due to the transaction simulation process, to obtain the expected gas price, which occurs prior to the minting of the PKP.

Before Lit.Action.executeJS is called with each run of the Circuit the nonce value for ContractActions will be recalculated by invoking getTransactionCount() on the provider.

If you are sending any value along with the Contract Action, make sure that it is specified correctly in wei.

import { FetchAction, ContractAction } from "lit-listener-sdk"

const fetchAction: FetchAction = {
  type: "fetch", // type
  priority: 1, // execution priority 
  baseUrl: "https://api.example.com", // baseUrl
  endpoint: "/data", // endPoint
  responsePath: "data.value", // responsePath
  apiKey: "your_api_key", // apiKey
  toSign: [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100], // toSign
  signCondition: [
    {
      type: "&&",
      operator: "==",
      value: "expected_value",
    },
  ], // signCondition
};

const contractAction: ContractAction = {
  type: "contract", // type
  priority: 2, // execution priority
  contractAddress: "0x6968105460f67c3bf751be7c15f92f5286fd0ce5", // contract address
  abi: [
     {
      constant: true,
      inputs: [{ name: "numberValue", type: "uint256" }],
      name: "your_function_name",
      outputs: [{ name: "", type: "uint256" }],
      payable: false,
      stateMutability: "external",
      type: "function",
      },
  ], // abi
  functionName: "your_function_name", // function name
  chainId: "polygon", // chainId
  providerURL: "https://polygon-provider-url.com" // provider URL
  nonce: 1, // nonce
  gasLimit: 100000, // gas Limit
  value: 0, // value
  maxPriorityFeePerGas: 1000, // max priority gas fee
  maxFeePerGas: 10000, // max fee per gas
  args: [20], // function arguments
};

const {unsignedTransactionDataObject, litActionCode} = await newCircuit.setActions(
    [
        fetchAction,
        contractAction
    ]
)

To easily generate the unsigned transaction data that is passed to executeJS (signed by your PKP) for Contract Actions, you can invoke the asynchronous LitListenerSDK helper function generateUnsignedTransactionData.

Contract Action Parameters:

If the from address passed to a ContractAction is left blank it will be populated with the minted PKP Address during execution of the Lit Action.

Fetch Action Parameters:

Custom Action Parameters:

When creating a CustomAction and invoking a Lit Action to sign unsigned transaction data you will need to pass in the unsigned transaction data as an argument, however you do not need need to include the PKP PublicKey, PKP Address or Auth Signature as arguments as these parameters are passed to Circuit.start()

Last updated