Skip to content

Latest commit

 

History

History
222 lines (175 loc) · 8.2 KB

File metadata and controls

222 lines (175 loc) · 8.2 KB
title Helius Solana SDKs: Node.js and Rust Development Tools
sidebarTitle Helius Solana SDKs
description Official Helius SDKs for Solana development in Node.js and Rust. Simplify blockchain integration with comprehensive APIs, enhanced transactions, and DAS support.

At Helius, we've developed a Node.js and a Rust SDK to make developing on Solana easier. The following page includes information on installing and using these SDKs. It also covers common error handling, where to find the latest documentation, and how to contribute to these SDKs.

We also outline a list of unofficial community SDKs made by our wonderful community. Note that those SDKs are not officially maintained by our team — only the Node.js and Rust SDKs are.

Official Helius Node.js SDK for Solana development Official Helius Rust SDK for Solana development

Node.js SDK

Note the Node.js SDK has been rewritten as of version 2.0.0. This was done to use @solana/kit and remove the dependency on @solana/web3.js versions higher than 1.73.2. For those migrating to the latest version, please refer to our migration guide.

Installation

The Helius Node.js SDK can be installed with any of the following package managers:

```bash npm install helius-sdk ``` ```bash pnpm install helius-sdk ``` ```bash yarn add helius-sdk ```

Quick Start

Below is a straightforward example of how to use the Node.js SDK to fetch a list of assets owned by a given address:

import { createHelius } from "helius-sdk";

(async () => {
  const apiKey = ""; // From Helius dashboard
  const helius = createHelius({ apiKey });

  try {
    const assets = await helius.getAssetsByOwner({
      ownerAddress: "owner_address_goes_here",
      page: 1,
      limit: 50,
      sortBy: { sortBy: "created", sortDirection: "asc" },
    });

    console.log("Fetched assets:", assets);
  } catch (error) {
    console.error("Error:", error);
  }
})();

Documentation

The examples directory is filled with in-depth code examples covering each method and basic usage, organized by namespace. For API reference documentation, refer to our documentation and the official Solana documentation for general Solana JSON RPC API help. For general help with Kit, please refer to Kit's documentation.

Rust SDK

Installation

To start using the Helius Rust SDK in your project, add it as a dependency via [`cargo`](https://doc.rust-lang.org/cargo/). Open your project's `Cargo.toml` and add the following line under `[dependencies]`:
```toml
helius = "x.y.z"
```

where `x.y.z` is your desired version.
Alternatively, use `cargo add helius` to add the dependency directly via the command line. This will automatically find the latest version compatible with your project and add it to your `Cargo.toml`. Remember to run `cargo update` regularly to fetch the latest version of the SDK.

Quick Start

Below is a straightforward example of using the Enhanced Transactions API to parse a given transaction:

use helius::error::Result;
use helius::types::*;
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
    let api_key: &str = "your_api_key";
    let cluster: Cluster = Cluster::MainnetBeta;

    let helius: Helius = Helius::new(api_key, cluster).unwrap();

    let request: ParseTransactionsRequest = ParseTransactionsRequest {
        transactions: vec![
            "2sShYqqcWAcJiGc3oK74iFsYKgLCNiY2DsivMbaJGQT8pRzR8z5iBcdmTMXRobH8cZNZgeV9Ur9VjvLsykfFE2Li".to_string(),
        ],
    };

    let response: Result<Vec<EnhancedTransaction>, HeliusError> = helius.parse_transactions(request).await;
    println!("Assets: {:?}", response);

    Ok(())
}

Documentation

Latest documentation on docs.rs Helius API documentation Code examples in the GitHub repo

Error Handling

An error message will be thrown when the API returns a non-success (i.e., 4xx or 5xx status code).

For example, below is a 401 thrown for an incorrect getAsset call using the Node.js SDK:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32001,
    "message": "Authentication failed. Missing or invalid API key."
  },
  "id": "1"
}

Common Error Codes

When working with the Helius SDK, you may encounter several error codes. Below is a table detailing some of the common error codes along with additional information to help you troubleshoot:

This occurs when a request has invalid parameters. This occurs when an invalid API key is provided or access is restricted due to RPC rules. This indicates that the user has exceeded the request limit in a given timeframe or is out of credits. This is a generic error message for server-side issues. Please contact Helius support for assistance.

If you encounter any of these errors:

Refer to [`errors.rs`](https://github.com/helius-labs/helius-rust-sdk/blob/dev/src/error.rs) for a list of all possible errors returned by the `Helius` client, if using the Rust SDK. For the Node.js SDK, refer to [Kit's errors](https://www.solanakit.com/docs/concepts/errors) Refer to the [Helius documentation](/) for further guidance Reach out to the Helius support team for more detailed assistance

Contribution to Our SDKs

We welcome all contributions to our SDKs! If you're interested, here are our GitHub Repositories:

Contribute to our Node.js SDK Contribute to our Rust SDK Interested in contributing to the Helius Rust SDK specifically? Read the following [contributions guide](https://github.com/helius-labs/helius-rust-sdk/blob/dev/CONTRIBUTIONS.md) before opening up a pull request!

Unofficial Community SDKs

Our amazing community members have also created their own SDKs to interact with our REST APIs. Please note our team does not officially maintain these.