# gsharpc user guide

Because gsharpc does not directly compile C# source code to hvm bytecode, you need to install Visual Studio 2017 (there is a free community version) or .Net Framework SDK to compile C# source code to .Net bytecode file first, and then use gsharpc compiles the .Net bytecode file dll file to convert to hvm bytecode, it is recommended to install Visual Studio 2017

You can configure the development environment by following these steps:

  1. Please install Visual Studio 2017 Community, and make sure that the C# development environment is selected for installation.
  2. Create a new C# class library project (.Net Framework) and add several .dll files of gsharpc to the "references" of the project. This project is used to write smart contracts or scripts on the chain. Ultimately, we are going to compile this project to hvm bytecode
  3. Referring to the example in the demo, Class1.cs is an example of the main supported syntax. DemoContract1.cs is an example of a smart contract. Modify Class1.cs of newly created project (recommended to be changed to other file name)
  4. Under the same Visual Studio solution, add and create a new C# console project (.Net Framework), add several .dll files of gsharpc in the project "reference", and add the class just created in the project reference Library project. This project is used to debug and call the smart contract C# code directly in Visual Studio. Set this project as the startup project of the solution
  5. In the C# console project created in step 4, you can run the project to debug and run the class library project created in step 2.
  6. Compile the entire solution, find the "{project name}.dll" in the bin/Debug or bin/Release folder of the class library project created in step 2 (depending on whether it is Debug or Release mode), this is what the project generates. dll file
  7. Execution gsharpc –gpc file.dllproduces "project name.gpc", which is the target contract .gpc file
  8. Use the generated .gpc file for subsequent actions such as registering contracts, calling contracts, and registering scripts
  9. If you want to write a contract and just want to execute the code, you need to use gsharpc -c file path .dll in step 5 to generate the "project name.out" file, which is the hvm bytecode file, and then you can use hvm file_path.outTo execute this bytecode file directly
  10. For the time being, try not to compile C# projects in Release mode. Release mode will optimize some null values ​​to 0, and 0 and hvm are inconsistent in hvm. Currently gsharpc does not support the dll generated by Release mode compilation.