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:
-
getLatestBlockhash -
createAccountWithSeed -
Message -
Instruction -
Transaction -
getMinimumBalanceForRentExemption -
sendTransaction
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
[]
= "0.7"
= "*" # add latest version
= "*" # add latest version
Or simple use cargo-edit crate
Generate a new Keypair
use OsRng;
use Keypair;
let mut csprng = OsRng;
let keypair: Keypair = generate;
Or import the ed25519_dalek::Keypair from bytes if you already have one
use Keypair;
// Example of the 64 bytes of both the secret key (32bytes) and
// public key (32bytes) respectively
let bytes = ;
let keypair: Keypair = from_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
use ;
Get the Minimum rent needed to pay storage costs for 2 years
use GetMinimumBalanceForRentExemption;
let two_year_rent =
.await?;
Creating a Program Derived Account
use ;
// Decide on the seed to create the PDA account for the program
let seed = "EXAMPLE_HELLO";
// Instantiate the PDA account builder
let mut pda = new;
let pda_public_key = pda
.add_from
.add_base
.add_lamports
.add_seed
.add_space
.add_owner
.derive_public_key?;
// Call `build()` to create the `SystemInstruction::CreateAccountWithSeed`
let pda_instruction = pda.build?;
Building a Message
use MessageBuilder;
let mut message_builder = new;
message_builder
.add_instruction
.add_payer
.build;
let mut message = new;
message.build?;
Get Latest Blockhash
use GetLatestBlockhash;
let blockhash = as_bytes.await?;
Create a Transaction
use Signer;
use 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.add_recent_blockhash;
// Use the keypair to sign a message
let signature = keypair.sign;
// Instantiate a new transaction with the `Message`
let mut transaction = new;
// Add the signature of the message
transaction.add_signature;
Send a transaction to a Solana RPC Node
use ;
let mut rpc = new;
let send_tx_response = rpc.prepare_transaction?.send.await?;
let send_tx_outcome = parse_tx;
Get a Transaction using it's hash
use GetTransaction;
let base58_signature = "44stjcK4f7RC7KNCorh9gzhQagpYoT9Tq775UFtYbn5gepRocHEeXrtG2JmzgTYKCx83pfBhWHiwLa6sC7f8Ruft";
let tx_resp = process.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