Core Concepts
1.4.1 Action Structure
An Action is the fundamental building block in the Actions specification. It represents a complete, self-contained blockchain interaction that can be embedded in various Web2 contexts. The Action structure is defined by the following TypeScript interface:
Let's break down each field:
title: A concise, user-friendly title for the action. This should clearly indicate the purpose of the action, e.g., "Send ETH", "Mint NFT", "Stake Tokens".
icon: An absolute HTTPS URL pointing to an icon image. This image should be in SVG, PNG, or WebP format. The icon visually represents the action and should be recognizable at various sizes.
description: A brief explanation of what the action does. This provides context to the user and should be clear enough for someone unfamiliar with blockchain technology to understand.
label: The text that will appear on the action button or UI element. It should be concise and action-oriented, e.g., "Send", "Mint", "Stake".
links: An optional array of LinkedAction objects. These represent subsequent actions or steps that can be taken after the main action is completed. This allows for the creation of multi-step or branching interactions.
error: An optional ActionError object that defines how errors should be presented to the user if something goes wrong during the action execution.
Example of a basic Action structure:
1.4.2 Linked Action Types
Linked Actions are a powerful feature of the Actions specification, allowing for the creation of complex, multi-step blockchain interactions. There are several types of Linked Actions, each serving a different purpose:
Link Action
A simple hyperlink to a specified URL. This is useful for directing users to external resources or documentation.
Example:
Reference Action
References another Action by its Content Identifier (CID). This allows for the creation of modular, reusable Actions.
Example:
Transaction Action (tx)
Represents a single blockchain transaction. This is used for interacting with smart contracts or sending transactions.
Example:
Multi-Transaction Action (tx-multi)
Represents multiple blockchain transactions that are executed in sequence or parallel.
Example:
Transfer Action
Represents a native currency transfer action, such as sending ETH.
Example:
These Linked Action types provide flexibility in creating complex blockchain interactions while maintaining a standardized structure.
1.4.3 Action Inputs
Action Inputs are a crucial part of the Actions specification, allowing for dynamic and interactive blockchain interactions. They define how data is collected from users or the environment to be used in the execution of an Action.
The basic structure of an Action Input is defined by the following interface:
Let's examine each field in detail:
type: Defines the type of input field. It can be one of the following:
'text': For free-form text input
'number': For numerical input
'radio': For selecting one option from a list
'select': For dropdown selection
id: A unique identifier for the input. This is used to reference the input value in other parts of the Action.
scope: Defines where the input originates. It can be either:
'USER': The input should be provided by the user
'GLOBAL': The input is handled globally by the client (e.g., user's wallet address)
label: A user-friendly label for the input field.
required: An optional boolean indicating whether the input is mandatory.
pattern: An optional string representing a regular expression pattern for input validation.
For selectable inputs (radio and select types), an extended interface is used:
This adds an options
array to define the selectable choices.
Examples of different input types:
Text Input:
Number Input:
Radio Input:
Select Input:
Global Input:
When designing Actions, it's important to consider the user experience and only request necessary information. Use appropriate input types and validation to ensure data integrity and improve user interaction.
1.4.4 Typed Action Parameters
Typed Action Parameters are used to specify the nature and origin of data used in actions. They provide a flexible way to define how values are obtained and used within an Action. There are five types of Action Parameters:
Constant Parameter
Represents fixed values that don't require user input.
Example:
Action Input
Represents user-provided input, as defined in the previous section.
Computed Input
Derived from other inputs through simple arithmetic operations.
Example:
Contract Read Input
Used to fetch data from a smart contract.
Example:
Referenced Parameter
Allows reuse of parameters across different parts of an action.
Example:
These Typed Action Parameters provide a powerful way to define and manipulate data within Actions, allowing for dynamic and context-aware blockchain interactions.
1.4.5 Error Handling and Success Responses
Proper error handling and success feedback are crucial for providing a good user experience in blockchain interactions. The Actions specification includes standardized ways to handle errors and communicate successful execution.
Error Handling
The ActionError
interface is used to define how errors should be presented to the user:
Example usage:
When implementing Actions, it's important to provide clear and actionable error messages. Consider different scenarios that might cause failures (e.g., network issues, insufficient funds, smart contract errors) and provide appropriate guidance to the user.
Success Responses
The ActionSuccessResponse
interface is used to communicate successful execution of an action:
Example usage:
The nextActionCid
field allows for chaining of actions, enabling more complex multi-step interactions.
When designing success responses:
Provide clear confirmation of what was accomplished
Include relevant details (e.g., transaction amount, recipient)
If applicable, guide the user on what they can do next
By implementing robust error handling and informative success responses, you can create Actions that are more user-friendly and provide a smoother interaction with blockchain functionality.
Last updated