diff --git a/README.md b/README.md index 18d492b..c544f64 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # Solana Actions and Blockchain Links (Blinks) +![npm](https://img.shields.io/npm/dm/@solana/actions) + +## Documentation + +Access the full API documentation +[here](https://solana-developers.github.io/solana-actions/). + [Read the docs to get started](https://solana.com/docs/advanced/actions) Watch this video tutorial on @@ -24,6 +31,83 @@ npm add @solana/actions - Typedocs for the `@solana/actions` SDK: - https://solana-developers.github.io/solana-actions/ +## Usage + +### `createActionHeaders` + +This function helps create headers for API calls by accepting key-value pairs as +input. + +Example Code Snippet is just below! + +```javascript +import { createActionHeaders } from "@solana/actions"; + +const headers = createActionHeaders({ + authorization: "Bearer YOUR_TOKEN", + "content-type": "application/json", +}); + +console.log(headers); // Output: { authorization: 'Bearer YOUR_TOKEN','content-type': 'application/json' } +``` + +### `Creating a Typed actions.json Payload` + +This function helps structure an actions.json payload with type safety, ensuring +parameters match the expected format. Check out the code snipets below! + +```javascript +import { createTypedPayload } from "@solana/actions"; + +const actionsPayload = createTypedPayload({ + action: "transfer", + params: { + from: "source_wallet_address", + to: "destination_wallet_address", + amount: 10, + }, +}); + +console.log(actionsPayload); +``` + +### `Creating a Typed GET Request Payload` + +This function simplifies creating typed GET request payloads for API calls. Code +snipets below! + +```javascript +import { createGetRequest } from "@solana/actions"; + +const getRequestPayload = createGetRequest({ + endpoint: "/wallets", + params: { + walletId: "12345", + }, +}); + +console.log(getRequestPayload); +``` + +### `Creating a Typed POST Response Payload Using createPostResponse` + +Use this function to create structured responses for POST requests with a +standardized format. + +```javascript +import { createPostResponse } from '@solana/actions'; + +const postResponse = createPostResponse({ + success: true, + data: { + id: '12345', + status: 'completed', + }, +}); + +console.log(postResponse); +`` + ## What are Solana Actions? [Solana Actions](https://solana.com/docs/advanced/actions#actions) are @@ -49,3 +133,4 @@ a URL. The Solana Actions JavaScript SDK is open source and available under the Apache License, Version 2.0. See the [LICENSE](./LICENSE) file for more info. +``` diff --git a/packages/solana-actions/README.md b/packages/solana-actions/README.md index 786879e..5cbbc82 100644 --- a/packages/solana-actions/README.md +++ b/packages/solana-actions/README.md @@ -1,5 +1,12 @@ # Solana Actions and Blockchain Links (Blinks) +![npm](https://img.shields.io/npm/dm/@solana/actions) + +## Documentation + +Access the full API documentation +[here](https://solana-developers.github.io/solana-actions/). + [Read the docs to get started](https://solana.com/docs/advanced/actions) Install the `@solana/actions` SDK into your application: @@ -13,6 +20,75 @@ npm add @solana/actions - Typedocs for the `@solana/actions` SDK: - https://solana-developers.github.io/solana-actions/ +## Usage + +### `createActionHeaders` + +This function helps create headers for API calls by accepting key-value pairs as input. + +Example Code Snippet is just below! + +```javascript +import { createActionHeaders } from '@solana/actions'; + +const headers = createActionHeaders({ authorization: 'Bearer YOUR_TOKEN', +'content-type': 'application/json', }); + +console.log(headers); // Output: { authorization: 'Bearer YOUR_TOKEN','content-type': 'application/json' } +``` + +### `Creating a Typed actions.json Payload` +This function helps structure an actions.json payload with type safety, ensuring parameters match the expected format. Check out the code snipets below! + +```javascript +import { createTypedPayload } from '@solana/actions'; + +const actionsPayload = createTypedPayload({ + action: 'transfer', + params: { + from: 'source_wallet_address', + to: 'destination_wallet_address', + amount: 10, + }, +}); + +console.log(actionsPayload); +``` + +### `Creating a Typed GET Request Payload` +This function simplifies creating typed GET request payloads for API calls. Code snipets below! + +```javascript +import { createGetRequest } from '@solana/actions'; + +const getRequestPayload = createGetRequest({ + endpoint: '/wallets', + params: { + walletId: '12345', + }, +}); + +console.log(getRequestPayload); +``` + +### `Creating a Typed POST Response Payload Using createPostResponse` +Use this function to create structured responses for POST requests with a standardized format. + +```javascript +import { createPostResponse } from '@solana/actions'; + +const postResponse = createPostResponse({ + success: true, + data: { + id: '12345', + status: 'completed', + }, +}); + +console.log(postResponse); +``` + + ## Developer resources Watch this video tutorial on