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:
[x] getLatestBlockhash
[x] createAccountWithSeed
[x] Message
Instruction
Transaction
getMinimumBalanceForRentExemption
sendTransaction
First, generate an Ed25519 Public and Private Keypair or import one. Use the ed25519_dalek
crate to generate or import the ed25519_dalek::Keypair
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 ```
```rust use rand::rngs::OsRng; use ed25519_dalek::Keypair;
let mut csprng = OsRng{}; let keypair: Keypair = Keypair::generate(&mut csprng); ```
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!!!```rust use borsh::{BorshDeserialize, BorshSerialize};
pub struct PoseidonTestStore { username: String, } ```
```rust use poseidon_client::GetMinimumBalanceForRentExemption;
let twoyearrent =
GetMinimumBalanceForRentExemption::process::
```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::
// Call build()
to create the SystemInstruction::CreateAccountWithSeed
let pda_instruction = pda.build()?;
```
```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)?; ```
```rust use poseidon_client::GetLatestBlockhash;
let blockhash = GetLatestBlockhash::as_bytes(Commitment::Finalized).await?; ```
```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());
```
```rust use poseidon_client::{RpcClient, TxSendOutcome};
let mut rpc = RpcClient::new(); let sendtxresponse = rpc.preparetransaction(&transaction)?.send().await?; let sendtxoutcome = TxSendOutcome::parsetx(sendtxresponse); ```
```rust use poseidon_client::GetTransaction;
let base58signature = "44stjcK4f7RC7KNCorh9gzhQagpYoT9Tq775UFtYbn5gepRocHEeXrtG2JmzgTYKCx83pfBhWHiwLa6sC7f8Ruft"; let txresp = GetTransaction::process(sign).await?; ```
This library is licensed under MIT
or Apache-2.0
and all contributions are licensed under the same licenses.
While making contributions, adhere to the Rust Code of Conduct