Action Types

Linked Actions support both fixed as well as parameterized values, as specified by the optional parameters attribute.

Parameterized actions signal to the client that users may provide a variable input for the action.

Apart from simple text input fields, ActionParameter now also accepts other input types as specified in ActionParameterType.

export interface LinkedAction {
  /** URL endpoint for an action */
  href: string;
  /** button text rendered to the user */
  label: string;
    /**
   * Parameters to accept user input within an action
   * @see {ActionParameter}
   * @see {ActionParameterSelectable}
   */
  parameters?: Array<TypedActionParameter>;
}

/** Parameter to accept user input within an action */
export interface ActionParameter {
  /** input field type */
  type?: ActionParameterType;
  /** parameter name in url */
  name: string;
  /** placeholder text for the user input field */
  label?: string;
  /** declare if this field is required (defaults to `false`) */
  required?: boolean;
  /** regular expression pattern to validate user input client side */
  pattern?: string;
  /** human-readable description of the `type` and/or `pattern`, represents a caption and error, if value doesn't match */
  patternDescription?: string;
  /** the minimum value allowed based on the `type` */
  min?: string | number;
  /** the maximum value allowed based on the `type` */
  max?: string | number;
}

/**
 * Input field type to present to the user
 * @default `text`
 */
export type ActionParameterType =
  | "text"
  | "email"
  | "url"
  | "number"
  | "date"
  | "datetime-local"
  | "checkbox"
  | "radio"
  | "textarea"
  | "select";
  
/**
 * note: for ease of reading, this is a simplified type of the actual
 */
interface ActionParameterSelectable extends ActionParameter {
  options: Array<{
    /** displayed UI label of this selectable option */
    label: string;
    /** value of this selectable option */
    value: string;
    /** whether or not this option should be selected by default */
    selected?: boolean;
  }>;
}

When type is set as select, checkbox, or radio then the Action should include an array of options as shown above in ActionParameterSelectable.

Only Linked Actions Support Parameters

Only linked actions support parameters. The Actions Spec extends Solana Pay and must remain interoperable with Solana Pay. As a result, all URLs that may be called via GET requests must also support POST requests. Parameterized actions are underspecified by construction, and therefore signable transactions are not possible via POST routes.

You can also build a blink with multiple input fields similar to the one in the previous section by a simple change in the structure of the GET response.

The following example demonstrates how you can structure the GET response to allow two different inputs - a custom SOL amount and a Thank You note.

{
 icon: '<image-url>',
 label: 'Donate SOL',
 title: 'Donate to Alice',
 description: 'Cybersecurity Enthusiast | Support my research with a donation.',
 links: {
  actions: [
    {
      href: `/api/donate/{${amountParameterName}}/{${thankYouNote}}`,
      label: 'Donate',
      parameters: [
        {
          name: amountParameterName,
          label: 'Enter a custom SOL amount',
        },
        {
          name: thankYouNote,
          label: 'Thank you note',
        },
      ],
    },
  ],
 },
}

The Blink would unfurl like this

NOTE: If you have any actions before this action with a label and custom href for predefined amounts of a parameter, it will be ignored when the Blink is unfurled

Last updated