✨
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

SDK Reference

The Actions SDK provides a set of tools and utilities to create, validate, and deploy Actions. This section provides an overview of the key components of the SDK.

1.5.1 Types and Interfaces

The SDK exports various types and interfaces from the actions-spec package. These are crucial for defining the structure of Actions and ensuring type safety in TypeScript projects. Some of the key types include:

  • Action: The main interface for defining an Action

  • LinkedAction: Represents actions that can be linked to the main Action

  • TxAction, TxMultiAction, TransferAction: Specific types of LinkedActions

  • ActionInput: Defines user inputs for Actions

  • TypedActionParameter: Represents different types of action parameters

  • ActionError: Defines the structure for error responses

  • ActionSuccessResponse: Defines the structure for success responses

To use these types in your project:

import { Action, LinkedAction, ActionInput } from '@actions/sdk';

const myAction: Action = {
    // Define your action here
};

1.5.2 Constants

The SDK provides several useful constants:

  1. chainId: An object mapping network names to their chain IDs.

    import { chainId } from '@actions/sdk';
    
    console.log(chainId.ETHEREUM_MAINNET); // Outputs: 1
    console.log(chainId.POLYGON_MAINNET); // Outputs: 137
    
  2. globalInputs: Constant values for global inputs.

    import { globalInputs } from '@actions/sdk';
    
    console.log(globalInputs.WALLET_ADDRESS); // Outputs: 'WALLET_ADDRESS'
    
  3. erc20FunctionSignatures: Mapping of ERC20 function names to their signatures.

    import { erc20FunctionSignatures } from '@actions/sdk';
    
    console.log(erc20FunctionSignatures.transfer);
    // Outputs: 'function transfer(address recipient, uint256 amount) returns (bool)'
    
  4. erc721FunctionSignatures: Mapping of ERC721 function names to their signatures.

    import { erc721FunctionSignatures } from '@actions/sdk';
    
    console.log(erc721FunctionSignatures.safeTransferFrom);
    // Outputs: 'function safeTransferFrom(address from, address to, uint256 tokenId)'
    

These constants can be useful for creating standardized Actions that interact with common contract types or need to reference specific blockchain networks.

1.5.3 Functions

The SDK provides two main functions for working with Actions:

validateAction(action: Action): { valid: boolean; errors: string[] | null }

This function validates an Action object against the Actions specification. It uses JSON Schema validation with the Ajv library to ensure the Action object conforms to the defined schema.

Usage:

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

const myAction = {
    // Define your action here
};

const { valid, errors } = validateAction(myAction);
if (valid) {
    console.log('Action is valid');
} else {
    console.error('Validation errors:', errors);
}

deployToIpfs(action: Action, pinataCredentials: PinataCredentials): Promise<string | Error>

This function deploys an Action to IPFS using Pinata as the pinning service. It returns a Promise that resolves to the IPFS hash of the deployed Action.

Usage:

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

const myAction = {
    // Define your action here
};

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

deployToIpfs(myAction, pinataCredentials)
    .then((ipfsHash) => console.log('Deployed to IPFS:', ipfsHash))
    .catch((error) => console.error('Deployment failed:', error));

These functions provide the core functionality needed to work with Actions, from creation and validation to deployment on IPFS.

PreviousCore ConceptsNextExamples

Last updated 6 months ago