Actions
Create Web3 Action
Create a new Web3 Action. You can also set the Web3 Action to be deployed once it's been created.
Validation
When the payload fails validation, the endpoint responds with 400 and the error slug found_validation_errors without per-field detail. Common causes:
- action.name doesn't match ^[a-zA-Z][a-zA-Z0-9_-]*$ (it must start with a letter and may contain only letters, digits, dashes, and underscores; spaces are not allowed). Put human-readable text in action.description instead.
- trigger.periodic.cron is not a standard five-field cron expression (minute, hour, day of month, month, day of week). Seconds fields and @hourly-style shortcuts are not supported.
- The function referenced in action.function is not present in action.source.
- action.trigger is missing for a non-ALERT trigger type, or the trigger object doesn't match triggerType.
- action.invocationType is not one of SYNC or ASYNC.
post/v1/account/{accountSlug}/project/{projectSlug}/actions/publishFile
Path parameters
accountSlugstring required
Account slug of the user
projectSlugstring required
Project slug of the account
Request body
Example request
{
"action": {
"name": "block-action",
"description": "Triggers on every 10th block on ETH Mainnet and Polygon.",
"source": "// Do not change function name.\nconst actionFn = async (context, blockEvent) => {\n console.log(blockEvent)\n\n // To access project's secret\n // let secret = await context.secrets.get('MY-SECRET')\n\n // To access project's storage\n // let value = await context.storage.getStr('MY-KEY')\n // await context.storage.putStr('MY-KEY', 'MY-VALUE')\n\n // Your logic goes here :)\n}\n// Do not change this.\nmodule.exports = { actionFn }",
"triggerType": "BLOCK",
"runtime": "V2",
"function": "actionFn",
"invocationType": "ASYNC",
"trigger": {
"type": "block",
"block": {
"network": [
"1",
"137"
],
"blocks": 10
}
}
},
"deploy": true
}Response
A successful response.
Example response
{
"actions": {
"block-action": {
"id": "349cbb00-64ad-47ec-bbcb-40bffa28559f",
"index": 1,
"actionId": "53712e55-eb77-4ce3-9140-685fd230396a",
"parentActionId": "",
"runtime": "V2",
"function": "implementation:actionFn",
"triggerType": "BLOCK",
"trigger": {
"type": "block",
"block": {
"network": [
"1",
"137"
],
"blocks": 10
}
},
"commitish": null,
"source": "// Do not change function name.\nconst actionFn = async (context, blockEvent) => {\n console.log(blockEvent)\n\n // To access project's secret\n // let secret = await context.secrets.get('MY-SECRET')\n\n // To access project's storage\n // let value = await context.storage.getStr('MY-KEY')\n // await context.storage.putStr('MY-KEY', 'MY-VALUE')\n\n // Your logic goes here :)\n}\n// Do not change this.\nmodule.exports = { actionFn }",
"createdAt": "2023-12-14T18:47:19.26565Z",
"deployRequested": true,
"deployError": null,
"invocationType": "ASYNC"
}
}
}