Author

Topic: BitcoinRpcSharp - A C# wrapper for the Bitcoin JSON RPC interface (Read 4277 times)

legendary
Activity: 1261
Merit: 1000
Congratualtions!

How can i donate in Bitcoin?

Why im getting this number?

...
add1= wallet.GetNewAddress();
             wallet.SetAccount(add1, "andre22");
             balance = wallet.GetBalance("andre22");


Is showing to me:

balance = 415855183323463.75M
newbie
Activity: 2
Merit: 0
Nice wrapper! looking forward to it  Cheesy
hero member
Activity: 765
Merit: 503
FYI, getting wrong account when using GetAccount(btcaddress) method, and account/label is null.
member
Activity: 113
Merit: 10
Hi!
I'm new in bitcoin system and i want to do some tests.
I've tried your application choosing method 17 (GetDifficulty).
But at the  MakeHttpRequest() method i received an exception : "System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly."

I set in app.config my ip and port number:
    http://myIP:8333"/>
   
   

Do you have an idea why i received this error? Exists another configurations to set?

Thank in advance!

Have a nice day.


Hi, you should only have to set those three settings.

Is it possible a firewall is blocking access to your bitcoind instance?
member
Activity: 113
Merit: 10
Anyone looking at this you need to download http://james.newtonking.com/json and reference it in the project before building it. Then in your own project reference the DLL from the debug folder.

Thanks for the heads up. In Visual Studio the NuGet package manager should automaticly install the needed DLL's. But for people who don't use Visual Studio or the package manager I added the link to the Json.NET site in the readme.
newbie
Activity: 1
Merit: 0
Hi!
I'm new in bitcoin system and i want to do some tests.
I've tried your application choosing method 17 (GetDifficulty).
But at the  MakeHttpRequest() method i received an exception : "System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly."

I set in app.config my ip and port number:
    http://myIP:8333"/>
   
   

Do you have an idea why i received this error? Exists another configurations to set?

Thank in advance!

Have a nice day.
member
Activity: 112
Merit: 10
Looking to start various enterprises
Anyone looking at this you need to download http://james.newtonking.com/json and reference it in the project before building it. Then in your own project reference the DLL from the debug folder.
member
Activity: 113
Merit: 10
Thanks Smiley. Let me know if you encounter any problems.
hero member
Activity: 714
Merit: 500
really really nice thanks a ton!
Honestly great work!
member
Activity: 113
Merit: 10
For a personal .net project of mine I was looking around for a way to interact with the Bitcoin wallet. I found some projects, but they were all outdated or writtin in the wrong language.

So as any programmer would do, I made my own C# wrapper of the JSON RPC interface which is offered by the standard Bitcoin wallet software. The project can be found on GitHub: https://github.com/BitKoot/BitcoinRpcSharp. I plan to add more features as I need them for my own projects.

I tried to keep to interface as similar to the JSON RPC interface as possible. I have provided a summary with every method offered. Most of it comes from the wiki, and I filled in the gaps where things were not immediatly clear.

The solution contains two projects.
- BitcoinRpcSharp: this is the library which contains the actual implementation (see below for examples). I have implemented about 95% of all RPC calls. Some calls are deprected, others are not relevant (like help). There are two methods which I need to look into more before I can complete the list of implemented methods: listlockunspent and lockunspent.
- TestConsoleApplication: this console application let's you invoke most of the methods from the command line (see below for an example). This application is to try out the Bitcoin wallet methods. It is not intended as a full fledged command line interface to the bitcoin wallet.

Library use examples
Let's get some information:
Code:
BitcoinWallet wallet = new BitcoinWallet("http://192.168.56.1:19001", "test", "123", false);
Info info = wallet.GetInfo();
Console.WriteLine("Current difficulty: {0}", info.Difficulty);

If we want to move some bitcoins to a newly generated address associated with a new account:
Code:
BitcoinWallet wallet = new BitcoinWallet("http://192.168.56.1:19001", "test", "123", false);
string newAddress = wallet.GetNewAddress("NewAccount");
bool success = wallet.Move("NewAccount", "OldAccount", 1m);

Or let's try something a bit more complicated: create a raw transaction, and sign it:
Code:
BitcoinWallet wallet = new BitcoinWallet("http://192.168.56.1:19001", "test", "123", false);

// Create an object containing the inputs and outputs of the transaction.
var createRawTransaction = new CreateRawTransaction();
createRawTransaction.AddInput("bfe0d11bdb73df37709a9f84fabf272576136bcd80589d52ab8ef35f25b48eda", 1); // Transaction id and output
createRawTransaction.AddOutput("n4AiGgWQvZtbo6vjnHWhXTB3ayYF3CFa55", 0.0001m); // Destination address and amount
createRawTransaction.AddOutput("mxDuX7VAPVEhDLtiMy5YgZSt1tLkss8e6G", 0.0001m); // Destination address and amount

// Get the hex string of the raw transaction
var unsignedHex = wallet.CreateRawTransaction(createRawTransaction);

// Sign the transaction, and get the hex string of the signed transaction
var signRawTransaction = new SignRawTransaction(unsignedHex); // This object can hold more information for complex scenario's
var signedTransaction = wallet.SignRawTransaction(signRawTransaction);

// Sent the signed transaction
wallet.SentRawTransaction(signedTransaction.Hex);

Test Console Application


The way to invoke a method is to enter it's number from the menu, followed by a comma separated list of arguments. For example, if we want to backup the wallet to D:\Backups, we would enter: 2,D:\Backups.

I would like to hear if people find this usefull, have suggestions or feature requests. Please be carefull when using this library, as some functions can really mess up your wallet. I have used and recommend the testnet in a box (https://github.com/freewil/bitcoin-testnet-box) for development.

I you are going to use my software, drop me a message. I always like to hear what you are using it for and if you have any requests or recommendations. And if you are feeling very filantropic, drop me a small tip at: 16rC9F5f5gWc3BNVDSX8Z9MRhcjWeRQ8uU.
Jump to: