Get up and running with Actions SDK in just a few steps:
Installation
Install the Actions SDK using npm:
Copy npm install @actions/sdk
Create a Simple Action
Here's a basic example of creating a simple transfer action:
Copy import { Action, TransferAction } from '@actions/sdk';
const myAction: Action = {
title: "Send ETH",
icon: "<https://example.com/eth-icon.png>",
description: "Send ETH to a specified address",
label: "Transfer ETH",
links: [
{
type: "transfer-action",
label: "Send 0.1 ETH",
address: {
type: "constant",
id: "recipientAddress",
value: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
},
value: "100000000000000000", // 0.1 ETH in wei
success: {
message: "Successfully sent 0.1 ETH!"
},
error: {
message: "Failed to send ETH. Please try again."
}
} as TransferAction
]
};
Validate the Action
Use the validateAction
function to ensure your Action is correctly structured:
Copy import { validateAction } from '@actions/sdk';
const { valid, errors } = validateAction(myAction);
if (valid) {
console.log('Action is valid');
} else {
console.error('Validation errors:', errors);
}
Deploy the Action
Deploy your Action to IPFS using the deployToIpfs
function:
Copy import { deployToIpfs } from '@actions/sdk';
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));
Use the Action
Once deployed, you can use the IPFS hash to reference and execute your Action in a Web3-enabled environment.
That's it! You've created, validated, and deployed your first Action. From here, you can explore more complex Actions, different types of linked actions, and advanced features of the Actions SDK.
Last updated 4 months ago