- This library would not be possible without Chris Williams.
A pure C# implementation for interacting with the XRP Ledger, the xrpl.c
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.
From RippleDotNet
using RippleDotNet;
using RippleDotNet.Model.Account;
using RippleDotNet.Requests.Account;
To xrpl.c
using Xrpl.Client;
using Xrpl.Client.Model.Account;
using Xrpl.Client.Requests.Account;
From Ripple.Core
using Ripple.Core.Types;
To xrpl.c
using Ripple.Binary.Codec.Types;
From Ripple.Signing
using Ripple.Signing;
To xrpl.c
using Xrpl.Wallet;
From Ripple.TxSigning
using Ripple.TxSigning;
To xrpl.c
using Ripple.Keypairs;
# create a network client
using Xrpl.Client;
IRippleClient client = new RippleClient("wss://s.altnet.rippletest.net:51233");
client.Connect();
# create a wallet on the testnet
using Xrpl.Wallet;
using System.Diagnostics;
// test_wallet = SOON
Debug.WriteLine(testWallet);
public_key: ED3CC1BBD0952A60088E89FA502921895FC81FBD79CAE9109A8FE2D23659AD5D56
private_key: -HIDDEN-
classic_address: rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo
# look up account info
using System.Diagnostics;
using Xrpl.Client.Model.Account;
AccountInfo accountInfo = await client.AccountInfo(account);
Debug.WriteLine(accountInfo);
# {
# "Account": "rBtXmAdEYcno9LWRnAGfT9qBxCeDvuVRZo",
# "Balance": "1000000000",
# "Flags": 0,
# "LedgerEntryType": "AccountRoot",
# "OwnerCount": 0,
# "PreviousTxnID": "73CD4A37537A992270AAC8472F6681F44E400CBDE04EC8983C34B519F56AB107",
# "PreviousTxnLgrSeq": 16233962,
# "Sequence": 16233962,
# "index": "FD66EC588B52712DCE74831DCB08B24157DC3198C29A0116AA64D310A58512D7"
# }
The xrpl.c
library is available on DotNet. Install with dotnet
:
dotnet add package xrpl.c --version 1.0.0
The library supports Dotnet 5 and later.
Use xrpl.c
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
xrpl.c
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 xrpl.c
reference documentation on Read the Docs.
The following sections describe some of the most commonly used modules in the xrpl.c
library and provide sample code.
Use the Xrpl.Client
library to create a network client for connecting to the XRP Ledger.
using Xrpl.Client;
IRippleClient client = new RippleClient("wss://s.altnet.rippletest.net:51233");
client.Connect();
Use the Xrpl.Wallet
module to create a wallet from a given seed or or via a Testnet faucet.
To create a wallet from a seed (in this case, the value generated using Xrpl.Keypairs
):
using Xrpl.Wallet;
using System.Diagnostics;
TxSigner signer = TxSigner.FromSecret(seed);
Debug.WriteLine(signer);
# pub_key: ED46949E414A3D6D758D347BAEC9340DC78F7397FEE893132AAF5D56E4D7DE77B0
# priv_key: -HIDDEN-
# classic_address: rG5ZvYsK5BPi9f1Nb8mhFGDTNMJhEhufn6
Use the Ripple.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 Ripple.Keypairs;
using System.Diagnostics;
Seed seed = Seed.FromRandom();
KeyPair pair = seed.KeyPair();
string public = pair.Id();
string private = seed.ToString();
Debug.WriteLine("Here's the public key:");
print("Here's the public key:")
Debug.WriteLine(public);
Debug.WriteLine("Here's the private key:");
Debug.WriteLine(private);
Debug.WriteLine("Store this in a secure place!");
# Here's the public key:
# ED3CC1BBD0952A60088E89FA502921895FC81FBD79CAE9109A8FE2D23659AD5D56
# Here's the private key:
# EDE65EE7882847EF5345A43BFB8E6F5EEC60F45461696C384639B99B26AAA7A5CD
# Store this in a secure place!
Note: You can use Ripple.Keypairs
to sign transactions but xrpl.c
also provides explicit methods for safely signing and submitting transactions. See Transaction Signing and XRPL Transaction Methods for more information.
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 xrpl.c
library provides several methods to simplify this process.
Use the xrpl.transaction
module to sign and submit transactions. The module offers three ways to do this:
-
safe_sign_and_submit_transaction
— Signs a transaction locally, then submits it to the XRP Ledger. This method does not implement reliable transaction submission best practices, so only use it for development or testing purposes. -
safe_sign_transaction
— Signs a transaction locally. This method does not submit the transaction to the XRP Ledger. -
send_reliable_submission
— An implementation of the reliable transaction submission guidelines, this method submits a signed transaction to the XRP Ledger and then verifies that it has been included in a validated ledger (or has failed to do so). Use this method to submit transactions for production purposes.
using Xrpl.Client.Model.Account;
using Xrpl.Client.Requests.Account;
using Xrpl.Client.Model.Transaction;
AccountInfo accountInfo = await client.AccountInfo("rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V");
# prepare the transaction
# the amount is expressed in drops, not XRP
# see https://xrpl.org/basic-data-types.html#specifying-currency-amounts
IPaymentTransaction paymentTransaction = new PaymentTransaction();
paymentTransaction.Account = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
paymentTransaction.Destination = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT";
paymentTransaction.Amount = new Currency { ValueAsXrp = 1 };
paymentTransaction.Sequence = accountInfo.AccountData.Sequence;
# sign the transaction
TxSigner signer = TxSigner.FromSecret("xxxxxxx"); //secret is not sent to server, offline signing only
SignedTx signedTx = signer.SignJson(JObject.Parse(paymentTransaction.ToJson()));
# submit the transaction
SubmitBlobRequest request = new SubmitBlobRequest();
request.TransactionBlob = signedTx.TxBlob;
Submit result = await client.SubmitTransactionBlob(request);
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;
Fee fee = await client.Fees();
Debug.WriteLine(fee);
# 10
If you want to contribute to this project, see CONTRIBUTING.md.
We have a low-traffic mailing list for announcements of new xrpl.c
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 xrpl.c
library is licensed under the ISC License. See LICENSE for more information.
The credit of this repository goes to Chris Williams.
https://github.com/chriswill
Thank you Chris.