Collection of newtypes for common solana types to implement serde on for easy use in web applications.
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
}
All individual newtypes are behind their own individual feature flag. All of them are enabled by default.
The non-default utoipa
feature implements utoipa::ToSchema for all the newtypes, allowing you to document them in openAPI/Swagger docs generated by utoipa
.