Code generation using the Visual Studio Code extension

Prerequisites:

Automatic code generation and the Nethereum Code generation settings file

The simplest way is to automatically code generate your api, for this you need to create a file called “nethereum-gen.settings” at the root of your project, with the following contents.

{
    "projectName": "Solidity.Samples",
    "namespace": "Solidity.Samples",
    "lang":0,
    "autoCodeGen":true
}
“lang” indicates what language to generate the code, 0 = CSharp, 1 = Vb.Net and 3 = FSharp

The “projectName” and “namespace” settings will be also used for the manual code generation.

Single smart contract manual code generation

Step 1:

In visual studio code, open the command palette with Ctrl+Shift+P. then type “solidity” and select “compile current Solidity contract”. Convert Solidity code to Json

You should now see a newly generated bin folder containing three generated files.

Step 2 Single contract:

Select the Json files contained in bin, then open the command palette, type solidity and select Solidity: Code generate CSharp from compilation output "contract.json"

If you work in Vb.Net or FSharp chose those instead.

Convert Json file to CS

Step 3 Multiple contracts:

Open the command palette, type solidity and select Solidity: Code generate CSharp project from all compiled files

If you work in Vb.Net or FSharp chose those instead.

Convert Json file to CS