Crates.io | pwr-rs |
lib.rs | pwr-rs |
version | |
source | src |
created_at | 2023-12-07 09:00:30.639408+00 |
updated_at | 2025-05-20 21:32:54.26204+00 |
description | Complete PWR Chain library in Rust |
homepage | https://pwrlabs.io/ |
repository | https://github.com/pwrlabs/pwrrs |
max_upload_size | |
id | 1060830 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
PWR Rust is a Rust library for interacting with the PWR network. It provides an easy interface for wallet management and sending transactions on PWR.
# latest official release (main branch)
cargo add pwr-rs
Play with Code Examples 🎮
Import the library:
use pwr_rs::{
Wallet,
RPC,
};
Set your RPC node:
let rpc = RPC::new("https://pwrrpc.pwrlabs.io/").await.unwrap();
Generate a new random wallet:
let wallet = Wallet::new_random(12);
Import wallet by Seed Phrase:
let seed_phrase = "your seed phrase here";
let wallet = Wallet::new(seed_phrase);
Get wallet address:
let address = wallet.get_address();
Get wallet seed phrase:
let seed_phrase = wallet.get_seed_phrase();
Get wallet balance:
let balance = wallet.get_balance().await;
Transfer PWR tokens:
wallet.transfer_pwr("recipientAddress".to_string(), "amount", "fee_per_byte").await;
Sending a transcation to the PWR Chain returns a Response object, which specified if the transaction was a success, and returns relevant data. If the transaction was a success, you can retrieive the transaction hash, if it failed, you can fetch the error.
use pwr_rs::Wallet;
async fn main() {
let seed_phrase = "your seed phrase here";
let wallet = Wallet::new(seed_phrase);
let amount = 1000;
let fee_per_byte = (wallet.get_rpc().await).get_fee_per_byte().await.unwrap();
let response = wallet.transfer_pwr("recipientAddress".to_string(), amount, fee_per_byte).await;
if response.success {
println!("Transaction Hash: {}", response.data.unwrap());
}
}
Send data to a VIDA:
use pwr_rs::Wallet;
async fn main() {
let seed_phrase = "your seed phrase here";
let wallet = Wallet::new(seed_phrase);
let vida_id = 123;
let data = vec!["Hello World!"];
let data_as_bytes: Vec<u8> = data.into_iter().flat_map(|s| s.as_bytes().to_vec()).collect();
let fee_per_byte = (wallet.get_rpc().await).get_fee_per_byte().await.unwrap();
let response = wallet.send_vida_data(vida_id, data_as_bytes, fee_per_byte).await;
if response.success {
println!("Transaction Hash: {}", response.data.unwrap());
}
}
Get RPC Node Url:
Returns currently set RPC node URL.
let url = rpc.get_node_url();
**Get Fee Per Byte: **
Gets the latest fee-per-byte rate.
let fee = rpc.get_fee_per_byte();
Get Balance Of Address:
Gets the balance of a specific address.
let balance = rpc.get_balance_of_address("0x...").await.unwrap();
Get Nonce Of Address:
Gets the nonce/transaction count of a specific address.
let nonce = rpc.get_nonce_of_address("0x...").await.unwrap();
If you consider to contribute to this project please read CONTRIBUTING.md first.
You can also join our dedicated channel for pwr-rs on the PWR Chain Discord
Copyright (c) 2025 PWR Labs
Licensed under the MIT license.