> For the complete documentation index, see [llms.txt](https://blinkz.gitbook.io/blinkz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blinkz.gitbook.io/blinkz/sdk/blinkz-actions-sdk/sdk-reference.md).

# 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:

```tsx
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.

   ```jsx
   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.

   ```jsx
   import { globalInputs } from '@actions/sdk';

   console.log(globalInputs.WALLET_ADDRESS); // Outputs: 'WALLET_ADDRESS'

   ```
3. `erc20FunctionSignatures`: Mapping of ERC20 function names to their signatures.

   ```jsx
   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.

   ```jsx
   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:

```jsx
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:

```jsx
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.
