Good luck getting this working after any .NET updates - I've adandoned .NET/MVC for Python/Flask now.
A C# .NET Core wrapper for the Blockstream Esplorer API with full API coverage. Allows you to call the block Explorer's Bitcoin (main and testnet) and Liquid API from within your project.
An example of how to use the BlockstreamEsplorerAPI class within a .NET Core app can be found in Program.cs.
Note: If you want to actually use C# to issue commands to a Bitcoin or Elements/Liquid node itself (e.g. to create transactions, check wallet balance, issue assets etc) then check out the dotnetcoreDynamicJSON-RPC code instead. That uses dynamic types to send RPC commands, meaning the code is brief and you can call whatever is listed here: https://bitcoin.org/en/developer-reference#bitcoin-core-apis, the extra RPC calls used by Elements/Liquid, and any future RPC commands, with little effort and no need to change the code within dotnetcoreDynamicJSON-RPC in the future.
//Bitcoin
Esplorer.APITarget = APITarget.bitcoin;
long testBlock = Esplorer.Blocks_Tip_Height();
string blockHash = Esplorer.Block_Height(testBlock);
Block block = Esplorer.Block(blockHash);
Console.WriteLine(block.height);
//Liquid
Esplorer.APITarget = APITarget.liquid;
long testBlock = Esplorer.Blocks_Tip_Height();
string blockHash = Esplorer.Block_Height(testBlock);
Block block = Esplorer.Block(blockHash);
//Liquid specific field:
Proof proof = block.proof;
Console.WriteLine(proof.challenge);
Examples of the Esplorer API:
https://blockstream.info/api/blocks
https://blockstream.info/liquid/api/blocks
https://blockstream.info/testnet/api/blocks
The Blockstream Esplorer website:
To use in your own project:
Copy BlockstreamEsplorerAPI.cs into your project.
Copy BlockstreamEsplorerClasses.cs into your project.
Reference the BlockstreamEsplorerAPI namepsace (using namespace BlockstreamEsplorerAPI;)
Reference the Newtonsoft.Json package in your .csproj file as done here.
You can switch to using Bitcoin testnet or Liquid using the Esplorer.APITarget property.
Program.cs contains a working example of all API calls using Esplorer's Bitcoin API.
If you don't have the .Net Core SDK:
The code targets version 2.1 of the .NET Core framework.
Register the Microsoft key and feed by choosing the Linux distribution you are using from the dotnet download site. It will give you the code to run and will look similar to this:
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Install the .NET SDK:
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.1
Using Visual Studio Code:
You don't need Visual Studio Code to edit the code, you can use any text editor. Visual Studio Code is a nice IDE and debugging in it is easy though, so it is easy to recommend. https://code.visualstudio.com
After installing Visual Studio Code you will need to add the C# language extension:
Open Visual Studio Code and click the "Tools and languages" box on the welcome screen. Select C# from the available extensions (id: ms-vscode.csharp).
Prerequisites and set up guides are listed and linked to here: https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code
If you already have the .NET Core SDK and Visual Studio Code with C# set up:
Note: The code targets version 2.1 of the .NET Core framework.
Clone this repository and then open the folder using Visual Studio Code's 'File/Open folder' option.
You will see two prompts:
"Required assets to build and debug are missing. Add them?"
- Click the 'Yes' buton.
"There are unresolved dependancies. Please execute the restore command to continue"
- Click the 'Restore' button.
Visual Studio 2017 (Windows only):
Clone this repository and then open the .csproj project file using Visual Studio's 'File/Open Project/Solution' option.
Questions or Issues? https://github.com/wintercooled/BlockstreamEsplorerAPI/issues
I'm on Twitter: https://twitter.com/wintercooled