PWRCS is a C# library for interacting with the PWR network. It provides an easy interface for wallet management and sending transactions on PWR.
- Generate wallets and manage keys
- Get wallet balance and nonce
- Build, sign and broadcast transactions
- Transfer PWR tokens
- Send data to PWR virtual machines
- interact with PWR nodes via RPC
- .NET 7.0
PWRCS is available on The NuGet Gallery. Add this dependency to your .csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PWRCS" Version="7.0.0" />
</ItemGroup>
</Project>
Import the library:
using PWRCS.*;
Set your RPC node:
var sdk = new PwrApiSdk("https://pwrrpc.pwrlabs.io/");
Generate a new wallet:
var wallet = new PwrWallet(sdk);
You also have the flexibility to import existing wallets using a variety of constructors
string privateKey = "private key"; //Replace with hex private key
var wallet = new PwrWallet(sdk,privateKey);
BigInteger privateKey = BigInteger.Parse("...");
var wallet = new PwrWallet(sdk,privateKey);
EthECKey ecKey = ...; //Generate or import ecKey
var wallet = new PwrWallet(sdk,ecKey);
Get wallet address:
string address = await wallet.GetAddress();
Get wallet balance:
ulong balance = await wallet.GetBalance();
Transfer PWR tokens:
var response = await wallet.TransferPWR("recipientAddress", amount);
Sending a transcation to the PWR Chain returns a ApiResponse 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.
ApiResponse r = await wallet.TransferPWR("recipientAddress", amount);
if(r.isSuccess) {
Console.WriteLine("Transcation Hash: " + r.Message);
} else {
Console.WriteLine("Error: " + r.Error);
}
Send data to a VM:
uint vmId = 123;
byte[] data = ...;
var r = await wallet.SendVmDataTxn(vmId, data);
if(r.isSuccess) {
Console.WriteLine("Transcation Hash: " + r.Message);
} else {
Console.WriteLine("Error: " + r.Error);
}
Update fee per byte:
Fetches latest fee-per-byte rate from the RPC node and updates the local fee rate.
await sdk.UpdateFeePerByte();
Get Fee Per Byte:
Gets the latest fee-per-byte rate.
ulong fee = await sdk.GetFeePerByte();
Get Balance Of Address:
Gets the balance of a specific address.
ulong balance = await sdk.GetBalanceOfAddress("0x...");
Get Nonce Of Address:
Gets the nonce/transaction count of a specific address.
uint nonce = await sdk.GetNonceOfAddress("0x...");
Broadcast Txn:
Broadcasts a signed transaction to the network.
byte[] signedTransaction = ...;
await sdk.BroadcastTxn(signedTransaction);
Pull requests are welcome!
For major changes, please open an issue first to discuss what you would like to change.