Poseidon - god of the Solana sea 😂

poseidon-client is a Minimal Solana Client library that aims to be fast to compile and cache friendly.

Currently, not all RPC methods are implemented. If you are looking for a feature rich Solana RPC library, take a look at Solana Anchor library or the official Solana SDK and Solana-client.

Current feature support include:

Usage

First, generate an Ed25519 Public and Private Keypair or import one. Use the ed25519_dalek crate to generate or import the ed25519_dalek::Keypair

Add dependencies

File: /Cargo.toml

toml [dependencies] rand = "0.7" ed25519-dalek = "*" # add latest version poseidon-client = "*" # add latest version

Or simple use cargo-edit crate

```sh $ cargo add rand --vers 0.7

$ cargo add ed25519-dalek

$ cargo add poseidon ```

Generate a new Keypair

```rust use rand::rngs::OsRng; use ed25519_dalek::Keypair;

let mut csprng = OsRng{}; let keypair: Keypair = Keypair::generate(&mut csprng); ```

Or import the ed25519_dalek::Keypair from bytes if you already have one

```rust use ed25519_dalek::Keypair;

// Example of the 64 bytes of both the secret key (32bytes) and // public key (32bytes) respectively let bytes = [0u8; 64]; let keypair: Keypair = Keypair::from_bytes(&bytes)?; ```

CAUTION : NOTE THAT PROTECTING THE SECRET KEY OF THE KEYPAIR IS BEYOND THE SCOPE OF THIS CRATE. TAKE CARE!!!

Create the data structure for serializing and deserializing the storage PDA account of the program

```rust use borsh::{BorshDeserialize, BorshSerialize};

[derive(Debug, BorshSerialize, BorshDeserialize)]

pub struct PoseidonTestStore { username: String, } ```

Get the Minimum rent needed to pay storage costs for 2 years

```rust use poseidon_client::GetMinimumBalanceForRentExemption;

let twoyearrent = GetMinimumBalanceForRentExemption::process::().await?; ```

Creating a Program Derived Account

```rust use poseidonclient::{SYSTEMPROGRAM_ID, PoseidonTestStore, PdaBuilder};

// Decide on the seed to create the PDA account for the program let seed = "EXAMPLE_HELLO";

// Instantiate the PDA account builder let mut pda = PdaBuilder::new(); let pdapublickey = pda .addfrom(keypair.public.tobytes()) .addbase(keypair.public.tobytes()) .addlamports(twoyearrent.result) .addseed(seed) .addspace(core::mem::sizeof::() as u64) .addowner(SYSTEMPROGRAMID) .derivepublic_key()?;

// Call build() to create the SystemInstruction::CreateAccountWithSeed let pda_instruction = pda.build()?; ```

Building a Message

```rust use poseidon_client::MessageBuilder;

let mut messagebuilder = MessageBuilder::new(); messagebuilder .addinstruction(pdainstruction) .addpayer(publickey_bytes) .build();

let mut message = Message::new(); message.build(message_builder)?; ```

Get Latest Blockhash

```rust use poseidon_client::GetLatestBlockhash;

let blockhash = GetLatestBlockhash::as_bytes(Commitment::Finalized).await?; ```

Create a Transaction

```rust use ed25519dalek::Signer; use poseidonclient::Transaction;

// First update the recent_blockhash field of the Message with // a recent blockhash so that transactions will not fail. // A Solana recent_blockhash only lasts for about 2 minutes in order to //prevent replay attacks message.addrecentblockhash(blockhash);

// Use the keypair to sign a message let signature = keypair.sign(&message.to_bytes()?);

// Instantiate a new transaction with the Message let mut transaction = Transaction::new(message); // Add the signature of the message transaction.addsignature(signature.tobytes()); ```

Send a transaction to a Solana RPC Node

```rust use poseidon_client::{RpcClient, TxSendOutcome};

let mut rpc = RpcClient::new(); let sendtxresponse = rpc.preparetransaction(&transaction)?.send().await?; let sendtxoutcome = TxSendOutcome::parsetx(sendtxresponse); ```

Get a Transaction using it's hash

```rust use poseidon_client::GetTransaction;

let base58signature = "44stjcK4f7RC7KNCorh9gzhQagpYoT9Tq775UFtYbn5gepRocHEeXrtG2JmzgTYKCx83pfBhWHiwLa6sC7f8Ruft"; let txresp = GetTransaction::process(sign).await?; ```

LICENSE

This library is licensed under MIT or Apache-2.0 and all contributions are licensed under the same licenses.

CODE OF CONDUCT

While making contributions, adhere to the Rust Code of Conduct