Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Solana Actions and Blockchain Links (Blinks)

# Solana Actions SDK

![npm](https://img.shields.io/npm/dw/@solana/actions)

The **Solana Actions SDK** simplifies the process of integrating typed action definitions into your Solana-related projects. With this SDK, you can create, validate, and handle typed payloads for GET and POST requests, ensuring type safety and consistent payload structures.

📚 **[Typedoc Documentation](https://solana-developers.github.io/solana-actions/)**

[Read the docs to get started](https://solana.com/docs/advanced/actions)

Watch this video tutorial on
Expand Down Expand Up @@ -45,6 +53,101 @@ Discord, a bot might expand the blink into an interactive set of buttons. This
pushes the ability to interact on-chain to any web surface capable of displaying
a URL.

## Usage Examples

Below are examples of some of the most common functions you can use with the Solana Actions SDK.

### 1. Create Action Headers

You can easily generate the headers required for your actions:

```javascript
import { createActionHeaders } from '@solana/actions';

const headers = createActionHeaders();

console.log(headers);
/*
{
"x-api-key": "your-api-key",
"x-user-token": "user-token",
"Content-Type": "application/json"
}
*/
```

### 2. Create a Typed actions.json Payload

```javascript
import { ActionGetResponse } from "@solana/actions";

const payload: ActionGetResponse = {
type: "action",
title: "Transfer SOL Example",
icon: "https://youricon.url/sol.png",
description: "Send SOL to a specified wallet address",
label: "Transfer SOL",
links: {
actions: [
{
label: "Send 1 SOL",
href: "/api/transfer-sol?amount=1",
},
{
label: "Send Custom Amount",
href: "/api/transfer-sol?amount={amount}",
parameters: [
{
name: "amount",
label: "Enter the amount",
required: true,
},
],
},
],
},
};

```

### Create a Typed GET Request Payload
```javascript
import { ActionGetResponse } from "@solana/actions";

export const GET = async (req: Request) => {
const payload: ActionGetResponse = {
type: "action",
title: "On-chain Memo Example",
icon: "https://youricon.url/memo.png",
description: "Send a memo to the blockchain",
label: "Send Memo",
};

return new Response(JSON.stringify(payload), {
headers: { "Content-Type": "application/json" },
});
};

```
### Create a Typed POST Response Payload
```javascript
import { ActionPostResponse, createPostResponse } from "@solana/actions";

export const POST = async (req: Request) => {
const responsePayload: ActionPostResponse = createPostResponse({
status: "success",
result: {
message: "Transaction successful!",
transactionId: "5tRfgh...",
},
});

return new Response(JSON.stringify(responsePayload), {
headers: { "Content-Type": "application/json" },
});
};
```

## License

The Solana Actions JavaScript SDK is open source and available under the Apache
Expand Down