✨
BLINKZ
  • Blinkz
    • Our Mission
    • Try It Now
    • Table of Contents
  • SDK
    • Blinkz Actions SDK
      • Introduction
      • Quick Start
      • Getting Started
      • Core Concepts
      • SDK Reference
      • Examples
      • Best Practices
      • How to Contribute
      • API Reference
      • Resources
      • FAQ
  • Extension
    • Blinkz Actions Extension
      • Overview
      • Key Components
      • Key Features
      • Usage
      • Development Status
      • Additional Resources
  • Generator
    • Blinkz Actions Generator
      • Overview
      • Key Components
      • Using The Actions Generator
      • Deployment
      • Extending The Generator
      • Additional Resources
  • Conclusion
    • Conclusion
Powered by GitBook
On this page
  1. SDK
  2. Blinkz Actions SDK

Getting Started

Installation

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:

  1. Import the necessary functions from the SDK:

import { validateAction, deployToIpfs } from '@actions/sdk';
  1. 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."
            }
        }
    ]
};
  1. Validate the Action:

Before deploying, it's crucial to validate your Action to ensure it conforms to the specification:

const { valid, errors } = validateAction(myAction);
if (!valid) {
    console.error('Action validation failed:', errors);
    return;
}
  1. Deploy the Action to IPFS:

If the Action is valid, you can deploy it to IPFS. This example uses Pinata as the IPFS pinning service:

const pinataCredentials = {
    apiKey: 'YOUR_PINATA_API_KEY',
    apiSecretKey: 'YOUR_PINATA_API_SECRET_KEY',
};

try {
    const ipfsHash = await deployToIpfs(myAction, pinataCredentials);
    console.log('Action deployed successfully! IPFS CID:', ipfsHash);
} catch (error) {
    console.error('Deployment failed:', error);
}
  1. Full Example:

Putting it all together, here's a complete example of creating, validating, and deploying an Action:

import { validateAction, deployToIpfs } from '@actions/sdk';

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."
            }
        }
    ]
};

async function deployMyAction() {
    // Validate the action
    const { valid, errors } = validateAction(myAction);
    if (!valid) {
        console.error('Action validation failed:', errors);
        return;
    }

    // Deploy to IPFS
    const pinataCredentials = {
        apiKey: 'YOUR_PINATA_API_KEY',
        apiSecretKey: 'YOUR_PINATA_API_SECRET_KEY',
    };

    try {
        const ipfsHash = await deployToIpfs(myAction, pinataCredentials);
        console.log('Action deployed successfully! IPFS CID:', ipfsHash);
    } catch (error) {
        console.error('Deployment failed:', error);
    }
}

deployMyAction();

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.

PreviousQuick StartNextCore Concepts

Last updated 6 months ago