A pure C# implementation for interacting with the XRP Ledger, the XrplCSharp library simplifies the hardest parts of XRP Ledger interaction, like serialization and transaction signing, by providing native C# methods and models for XRP Ledger transactions and core server API (rippled) objects.
// create a network client
using System.Diagnostics;
using Xrpl.Client;
var client = new XrplClient("wss://s.altnet.rippletest.net:51233");
client.OnConnected += async () =>
{
Debug.WriteLine("CONNECTED");
};
await client.Connect();
// create a wallet on the testnet
XrplWallet testWallet = XrplWallet.Generate();
await WalletSugar.FundWallet(client, testWallet);
Debug.WriteLine(testWallet);
// public_key: ED3CC1BBD0952A60088E89FA502921895FC81FBD79CAE9109A8FE2D23659AD5D56
// private_key: -HIDDEN -
// classic_address: rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo
// look up account info
string account = "rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo";
AccountInfoRequest request = new AccountInfoRequest(account);
AccountInfo accountInfo = await client.AccountInfo(request);
Debug.WriteLine(accountInfo);The Xrpl library is available on NuGet. Install with dotnet:
dotnet add package Xrpl
The library supports .NET 8, .NET 9, and .NET 10.
Use XrplCSharp to build C# applications that leverage the XRP Ledger. The library helps with all aspects of interacting with the XRP Ledger, including:
- Key and wallet management
- Serialization
- Transaction Signing
XrplCSharp also provides:
- A network client — See xrpl.clients for more information.
- Methods for inspecting accounts — See XRPL Account Methods for more information.
- Codecs for encoding and decoding addresses and other objects — See Core Codecs for more information.
See the complete XrplCSharp reference documentation.
The following sections describe some of the most commonly used modules in the XrplCSharp library and provide sample code.
Use the Xrpl.Client library to create a network client for connecting to the XRP Ledger.
using System.Diagnostics;
using Xrpl.Client;
var client = new XrplClient("wss://s.altnet.rippletest.net:51233");
client.OnConnected += async () =>
{
Debug.WriteLine("CONNECTED");
};
await client.Connect();Use the Xrpl.Wallet module to create a wallet from a given seed or via a Testnet faucet.
To create a wallet from a seed (in this case, the value generated using Xrpl.Keypairs):
using System.Diagnostics;
using Xrpl.Wallet;
// ...
string seed = "s";
XrplWallet wallet = XrplWallet.FromSeed(seed);
Debug.WriteLine(wallet);
// pub_key: ED46949E414A3D6D758D347BAEC9340DC78F7397FEE893132AAF5D56E4D7DE77B0
// priv_key: -HIDDEN-
// classic_address: rG5ZvYsK5BPi9f1Nb8mhFGDTNMJhEhufn6To create a wallet from a Testnet faucet:
using System.Diagnostics;
using Xrpl.Wallet;
XrplWallet testWallet = XrplWallet.Generate();
await WalletSugar.FundWallet(client, testWallet);
Debug.WriteLine(testWallet.ClassicAddress);
// Classic address: rEQB2hhp3rg7sHj6L8YyR4GG47Cb7pfcuwUse the Xrpl.Keypairs module to generate seeds and derive keypairs and addresses from those seed values.
Here's an example of how to generate a seed value and derive an XRP Ledger "classic" address from that seed.
using System.Diagnostics;
using Xrpl.Wallet;
// ...
XrplWallet wallet = XrplWallet.Generate();
string publicKey = wallet.PublicKey;
string privateKey = wallet.PrivateKey;
Debug.WriteLine("Here's the public key:");
Debug.WriteLine(publicKey);
Debug.WriteLine("Here's the private key:");
Debug.WriteLine(privateKey);
Debug.WriteLine("Store this in a secure place!");To securely submit transactions to the XRP Ledger, you need to first serialize data from JSON and other formats into the XRP Ledger's canonical format, then to authorize the transaction by digitally signing it with the account's private key. The XrplCSharp library provides several methods to simplify this process.
using System.Diagnostics;
using Xrpl.Models.Transactions;
using Xrpl.Models.Methods;
using Xrpl.Sugar;
string classicAddress = "rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo";
AccountInfoRequest request = new AccountInfoRequest(wallet.ClassicAddress);
AccountInfo accountInfo = await client.AccountInfo(request);
Payment tx = new Payment()
{
Account = wallet.ClassicAddress,
Destination = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT",
Amount = new Xrpl.Models.Common.Currency { ValueAsXrp = 1 },
};
TransactionSummary response = await client.SubmitAndWait(tx, wallet);
Debug.WriteLine(response);In most cases, you can specify the minimum transaction cost of "10" for the fee field unless you have a strong reason not to. But if you want to get the current load-balanced transaction cost from the network, you can use the Fees function:
using System.Diagnostics;
using Xrpl.Models.Transactions;
FeeRequest feeRequest = new FeeRequest();
Fee fee = await client.Fee(feeRequest);
Debug.WriteLine(fee);
// 10If you want to contribute to this project, see CONTRIBUTING.md.
We have a low-traffic mailing list for announcements of new XrplCSharp releases. (About 1 email per week)
If you're using the XRP Ledger in production, you should run a rippled server and subscribe to the ripple-server mailing list as well.
The XrplCSharp library is licensed under the Apache License 2.0. See LICENSE for more information.
This project is originally based on work by Chris Williams.
Currently maintained and developed by StaticBit-io.