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.
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:
Fetch Action Parameters:
Custom Action Parameters:
Last updated