Crate sanctum_solana_serde

Crate sanctum_solana_serde 

Source
Expand description

§sanctum-solana-serde

Collection of newtypes for common solana types to implement serde on for easy use in web applications.

§Examples

§Using B64VersionedTx with Jupiter Swap API

Let’s say you’re building an application that calls Jupiter Swap API’s /swap endpoint. You can use B64VersionedTx to handle deserialization of the API response for you:

use sanctum_solana_serde::b64_versioned_tx::B64VersionedTx;
use serde::Deserialize;

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JupSwapResp {
    pub swap_transaction: B64VersionedTx,
    pub last_valid_block_height: u64, // note: jup API serializes this as a json number, not a string
}
use reqwest::Client;
use solana_sdk::transaction::VersionedTransaction;

async fn get_swap_tx_from_jup(
    client: &Client,
    post_params: serde_json::Value
) -> VersionedTransaction {
    let JupSwapResp {
        swap_transaction,
        ..
    } = client.post("https://quote-api.jup.ag/v6/swap")
        .json(post_params)
        .send()
        .await
        .unwrap()
        .json()
        .await
        .unwrap();
    swap_transaction.0
}

§Features

All individual newtypes are behind their own individual feature flag. All of them are enabled by default.

§utoipa

The non-default utoipa feature implements utoipa::ToSchema for all the newtypes, allowing you to document them in openAPI/Swagger docs generated by utoipa.

Modules§

b58_pubkeyb58_pubkey
b58_signatureb58_signature
b64_bufferb64_buffer
b64_legacy_txb64_legacy_tx
b64_versioned_txb64_versioned_tx
decimal_strdecimal_str
u64_stru64_str
utoipa_schemautoipa