To begin working with Actions, you'll need to install the Actions SDK. This can be done using npm, the Node.js package manager. Open your terminal and run the following command:
npm install @actions/sdk
This command installs the latest version of the Actions SDK in your project.
Basic Usage
Once you have installed the SDK, you can start creating and deploying Actions. Here's a step-by-step guide to creating, validating, and deploying a simple Action:
Import the necessary functions from the SDK:
import { validateAction, deployToIpfs } from '@actions/sdk';
Create your Action:
Define your Action object according to the Actions specification. Here's a simple example:
const myAction = {
title: "Donate ETH",
icon: "<https://example.com/donate-icon.png>",
description: "Donate ETH to support our project",
label: "Donate Now",
links: [
{
type: "transfer-action",
label: "Donate 0.1 ETH",
address: {
type: "constant",
id: "projectAddress",
value: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
},
value: "100000000000000000", // 0.1 ETH in wei
success: {
message: "Thank you for your donation!"
},
error: {
message: "Donation failed. Please try again."
}
}
]
};
Validate the Action:
Before deploying, it's crucial to validate your Action to ensure it conforms to the specification:
This basic usage guide provides a foundation for working with Actions. As you become more familiar with the specification and SDK, you can create more complex Actions with multiple steps, computed inputs, and contract interactions.