From 1c4917667582d7b436c8a4e715b982a9512368b8 Mon Sep 17 00:00:00 2001 From: ThankGod Kalu Date: Wed, 20 Nov 2024 06:57:42 +0100 Subject: [PATCH] Update readme to include more useful information Update the readme to include more useful information with example code snippets. --- README.md | 147 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 114 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 18d492b..3a65fd0 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,132 @@ # Solana Actions and Blockchain Links (Blinks) -[Read the docs to get started](https://solana.com/docs/advanced/actions) +[![npm version](https://img.shields.io/npm/v/@solana/actions)](https://www.npmjs.com/package/@solana/actions) +[![npm downloads](https://img.shields.io/npm/dm/@solana/actions)](https://www.npmjs.com/package/@solana/actions) -Watch this video tutorial on -[How to Build Solana Actions](https://youtu.be/kCht01Ycif0) +## Overview -Find -[more resources for Solana Actions and blinks](https://solana.com/solutions/actions) +The `@solana/actions` SDK provides specification-compliant APIs to simplify blockchain transactions on the Solana network. This SDK enables developers to preview, sign, and send transactions across various contexts, such as QR codes, buttons, widgets, and websites, without navigating to separate apps or web pages. -Find example code snippets on how to build several different Solana Actions: +### Key Features +- **Solana Actions**: Integrate Solana transactions effortlessly into your app with standardized APIs. +- **Blockchain Links (Blinks)**: Shareable, metadata-rich links that work seamlessly across browsers, wallets, and bots. +- **Cross-Platform Compatibility**: Use in web apps, Discord bots, or any web environment capable of displaying URLs. -- [Deployed sample code snippets](https://solana-actions.vercel.app/) -- [Source code for code snippets](https://github.com/solana-developers/solana-actions/tree/main/examples/next-js) +For detailed documentation, visit the [Typedoc Docs](https://solana-developers.github.io/solana-actions/). -Install the `@solana/actions` SDK into your application: +--- -```shell +## Installation + +To integrate `@solana/actions` into your project, use npm: + +```bash npm add @solana/actions ``` -- `@solana/actions` SDK on NPM: - - https://www.npmjs.com/package/@solana/actions -- Typedocs for the `@solana/actions` SDK: - - https://solana-developers.github.io/solana-actions/ +For additional details, check the [@solana/actions SDK on NPM](https://www.npmjs.com/package/@solana/actions). + +--- + +## Getting Started + +### Example Code Snippets -## What are Solana Actions? +Here are examples of the most common functionalities provided by the `@solana/actions` SDK: -[Solana Actions](https://solana.com/docs/advanced/actions#actions) are -specification-compliant APIs that return transactions on the Solana blockchain -to be previewed, signed, and sent across a number of various contexts, including -QR codes, buttons + widgets, and websites across the internet. Actions make it -simple for developers to integrate the things you can do throughout the Solana -ecosystem right into your environment, allowing you to perform blockchain -transactions without needing to navigate away to a different app or webpage. +#### 1. **Creating Action Headers** + +```javascript +import { createActionHeaders } from '@solana/actions'; + +const headers = createActionHeaders({ + apiKey: 'your-api-key', + userAgent: 'YourApp/1.0', +}); + +console.log(headers); +``` -## What are blockchain links (blinks)? +#### 2. **Creating a Typed `actions.json` Payload** -[Blockchain links](https://solana.com/docs/advanced/actions#blinks) – or blinks -– turn any Solana Action into a shareable, metadata-rich link. Blinks allow -Action-aware clients (browser extension wallets, bots) to display additional -capabilities for the user. On a website, a blink might immediately trigger a -transaction preview in a wallet without going to a decentralized app; in -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. +```javascript +import { ActionPayload } from '@solana/actions'; + +const payload: ActionPayload = { + name: 'transfer-sol', + version: '1.0.0', + metadata: { description: 'A simple transfer action' }, + instructions: [ + { + programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + accounts: [ + { pubkey: 'SourceAccountPublicKey', isSigner: true, isWritable: true }, + { pubkey: 'DestinationAccountPublicKey', isSigner: false, isWritable: true }, + ], + data: 'TransactionDataInBase58', + }, + ], +}; + +console.log(payload); +``` + +#### 3. **Creating a Typed `GET` Request Payload** + +```javascript +import { createGetRequest } from '@solana/actions'; + +const getRequest = createGetRequest({ + endpoint: '/api/v1/action', + query: { actionId: 'example-action-id' }, +}); + +console.log(getRequest); +``` + +#### 4. **Creating a Typed `POST` Response Payload** + +```javascript +import { createPostResponse } from '@solana/actions'; + +const postResponse = createPostResponse({ + status: 200, + body: { + success: true, + message: 'Action completed successfully!', + }, +}); + +console.log(postResponse); +``` + +--- + +## Additional Resources + +- **Documentation**: [Typedoc Docs](https://solana-developers.github.io/solana-actions/) +- **Video Tutorial**: [How to Build Solana Actions](https://youtu.be/kCht01Ycif0) +- **Deployed Code Snippets**: [Solana Actions Examples](https://solana-actions.vercel.app/) +- **Source Code**: [Solana Actions on GitHub](https://github.com/solana-developers/solana-actions/tree/main/examples/next-js) + +--- + +## What Are Solana Actions? + +[Solana Actions](https://solana.com/docs/advanced/actions#actions) are standardized APIs that enable developers to perform blockchain transactions on Solana. These APIs allow transactions to be previewed, signed, and sent directly from applications, making it easy to integrate blockchain functionality without requiring users to navigate away from the current page. + +--- + +## What Are Blockchain Links (Blinks)? + +[Blockchain links](https://solana.com/docs/advanced/actions#blinks), or **blinks**, transform Solana Actions into shareable, metadata-rich links. These links can be used in wallets, bots, and other platforms to enhance user interactions. For example: +- On a website: Blinks trigger transaction previews in wallets. +- In Discord: Bots expand blinks into interactive buttons. + +--- ## License -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. +The Solana Actions SDK is open-source and available under the Apache License, Version 2.0. For more details, see the [LICENSE](./LICENSE) file. + +---