Installing Visual Studio on OSX

This article will show you how to set up Visual Studio so that you can run C# code that interacts with the Stratis blockchain.

If you are using Windows, the instructions are here.

If you would rather have your dev environment hosted on an Azure cloud server, the instructions are here.

Download and install Visual Studio Community Edition


  • Click here to download the latest version of Visual Studio Community for Mac.


    1. Open the downloaded Visual Studio .dmg file and follow the instructions.
    2. Install the .Net Core shown under Platforms during the installation process . You can uncheck the remaining options i.e. macOs, Android, iOS, if you don’t require to develop mobile or mac applications. Screenshot below:


  1. After installation completes, Open the Visual Studio from Applications.

    Create a console project

  2. Open Visual Studio and click on New Project as shown below:


  1. Under .Net Core from left navigation menu, Select App.
  2. Select Console Application under General and click Next Screenshot below:


  1. Provide a name to your application as shown below:


  1. Click Create button to create .Net core console application with default template.

Add the NStratis Nuget package as a resource

You can either use Nuget package manager console or Visual Studio GUI to add nStratis package into your solution.

Using npm

Install-Package nStratis -Version

Using Visual Studio GUI

  1. From left navigation menu, Select Dependencies. From top menu, Select Project and click on Add Nuget Packages. Screenshot below:


  1. Search Nstratis in the search bar present in the top right corner of the window.
  2. Select Nstratis from the search results and click on Add Package. Screenshot below:


  1. Install the package. Nstratis successfully added message appears after package is added to the solution successfully.

    Paste sample code into the program.cs

  2. Add the following using directive at the top of Program.cs file: using NBitcoin;
  3. Copy and paste the sample code below inside the method static void Main(string[] args).

         Key privateKey = new Key();
         PubKey publicKey = privateKey.PubKey;
         Console.WriteLine($"Public Key: {publicKey}");
         Console.WriteLine($"Public key hash: {publicKey.Hash}");
         Console.WriteLine($"Stratis testnet address: {publicKey.GetAddress(Network.StratisTest)}");
         Console.WriteLine($"Statis mainnet address: {publicKey.GetAddress(Network.StratisMain)}");
  4. Complete code for Program.cs file should look similar to screentshot below: image

    Add a debug mark

    Click on the vertical grey bar to add a breakpoint as shown in the screenshot below:


Run and step through the code

  1. Run the application in debug mode by pressing F5 or CMD+ENTER key.
  2. A blank terminal window will open and stop at the breakpoint set in previous step. Screenshot below:


  1. Press F10 to step over each line of code. Hover over an specific variable to check the value at run time. Screenshot below:


  1. Press F5 to continue execution of the application.
  2. Check terminal window for the output of the code as shown below:


Congratulations!🎉 . You have now successfully created a new Console project and interacted with the Stratis Blockchain.

Article written by @ashirvad-github (can be contacted on our Discord) Tip @ashirvad-github with Stratis here