Logs & Error Handling

Lit Action Responses and SDK Logs.

The getLogs method retrieves and returns the logs of the circuit. The logs provide a chronological record of events and actions that have taken place in the execution of the circuit. This can be helpful for debugging purposes or for recording the progression of circuit tasks.

You can optionally specify a category to get logs of that category only. There are three categories:

  • Error: Returns errors logged in the circuit.

  • Response: Returns a stringified JSON of the Lit Action response object.

  • Condition: Returns the matched or unmatched status for each conditional check and the Emitted Value from the Contract or Webhook Event.

  • Broadcast: Returns the broadcast Transaction Hash for broadcast ContractActions.

  • Execution: Returns when Conditional Logic or Execution Constraints are updated.

The SDK retains a rolling log of the most recent 1000 entries; for more extensive or permanent log storage, please consider using an external database or logging service.

import { LogCategory } from "lit-listener-sdk"

/* returns all logs recorded by the circuit.*/
const allLogs = newCircuit.getLogs()

/* the returned value is array of objects with both category, message and responseObject fields, the category is the enum type and the message is the log description and the responseObject is the returned response object.*/
const { category, message, responseObject } = allLogs[0];

/* returns only the error logs recorded by the circuit.*/
const errorLogsOnly = newCircuit.getLogs(LogCategory.Error)

When a log is recorded a log event is also emitted. You can subscribe to the events in real time through the .on method.

import { ILogEntry } from "lit-listener-sdk"

newCircuit.on('log', (logEntry: ILogEntry) => {
    console.log("new log recorded", logEntry);
})

Lit Action Response Object

The Response returned by the Lit.Actions.setResponse() method is a concatenated response object of all responses logged in the code, including error handling. It is found as a stringified JSON in the responseObject.response field of the returned log.

Every action is wrapped in a function with a unique name based on its type and priority, for example custom0, fetch1, contract2, etc.

When an action is executed the result is saved in the concatenatedResponse object under a key with the same name as the action function.

If you have a CustomAction with a priority of 0, and that action function returns the string "Custom Action 1", then the concatenatedResponse object will have a key-value pair of: custom0: "Custom Action 1".

For ContractActions the returned response value is the generatedUnsignedTransactionData, for FetchActions the returned response value is an object value found at the response path under the value key, and a boolean under signed, indicating whether the transaction was signed or not according to any signCondition. For CustomActions the custom indicated response object is returned.

Any console logs or signatures created when executing the Lit Action are also returned in the responseObject under the signatures and logs fields.

Each signature is named according to the SetAction type and priority order for FetchActions and ContractActions.

{
    category: 1,
    message: "Circuit executed successfully. Lit Action Response."
    responseObject: {
        signatures: {
            
            },
        response: {
            custom0: "Custom Action 1 Returned Response",
            contract1: {
                "to": "0x46C0Fa7Ef8384E356C62E7e4cC2578bD70D829aa",
                "nonce": 0,
                "chainId": 137,
                "gasLimit": "50000",
                "maxFeePerGas": "2601315606",
                "maxPriorityFeePerGas": "650328901",
                "from": "0x4F9DDeb2Fe6AB63809dC6A026F493B77F7df4400",
                "data": "0xa9059cbb00000000000000000000000046c0fa7ef8384e356c62e7ecc2578bd70d829aa0000000000000000000000000000000000000000000000016345785d8a0000",
                "value": 0,
                "type": 2
            },
            fetch2: {
                value: "returned fetch value",
                signed: true,
            } 
        }
        logs: "",
    }
  date: "2023-07-23T12:34:56.789Z"
}

Last updated