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 ActionLinkedAction
: Represents actions that can be linked to the main ActionTxAction
,TxMultiAction
,TransferAction
: Specific types of LinkedActionsActionInput
: Defines user inputs for ActionsTypedActionParameter
: Represents different types of action parametersActionError
: Defines the structure for error responsesActionSuccessResponse
: 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:
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
globalInputs
: Constant values for global inputs.import { globalInputs } from '@actions/sdk'; console.log(globalInputs.WALLET_ADDRESS); // Outputs: 'WALLET_ADDRESS'
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)'
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.
Last updated