C# SDK Introduction¶
Tags: “FISCOBCOS CSharp SDK” “‘C# sdk``
Software Architecture¶
Software Architecture Description
FISCOBCOS C# Sdk uses net core 3.1, and the supporting development tools are vs Code and Visual Studio 2019。
Function Introduction¶
Implement RPC synchronous / asynchronous requests
Realize the generation of public and private keys and accounts of FISCO BCOS, expand the generation of Webase Front, import the user json, and directly import the Webase middleware。
Implement contract operation encapsulation, such as contract deployment, request parameter construction, transaction signature, RLP encoding conversion, etc。
Realize contract deployment, contract trading, contract Call operation, contract transaction receipt acquisition, etc。
Realize the analysis of contract input, output, event, etc。
Unit test Demo for all operation configurations。Can reference copy。
Realize state secret support, create state secret accounts, deploy contracts under state secrets, trade, etc。
Note: Sending a transaction and returning a transaction receipt test synchronously has a certain chance of being empty because the underlying transaction is being packaged and consensus has not yet been completed。At present, the latest code adds polling acquisition to optimize the transaction receipt method and improve the user experience。
Installation Tutorial¶
Note: You can also use the webase-front blockchain middleware to export contracts to obtain abi and bin files。
Download the source code, vs2019 nuget package restore; Or use the nuget package to install, the installation command is as follows: Install-Package FISCOBCOS. CSharpSdk-Version 1.0.0.6
install the solidity plug-in in vs code and create a folder in vs code to store the original sol contract。
vs code executes the compilation command “compile current Solidity contract” according to F5, and abi and bin corresponding to the contract will be generated。
Put the abi and bin compiled above into your project and do the related operations。
Reference:

Instructions for use¶
Configure the BaseConfig file in the FISCOBCOS. CSharpSdk class library and configure the corresponding underlying request DefaultUrl, for example:http://127.0.0.1:8545 。
Use ContractService and QueryApiService for related business operations。
ContractService is mainly a package of operations such as contract calls, see the ContractTest.cs in the corresponding unit test in detail。
QueryApiService is the underlying non-transactional Json RPC API encapsulation. For more information, see Unit test ApiServiceTest.cs。
For more information, see RedisThreadWorkTest in the ConsoleTest project to enable multiple RedisSubClient projects for subscription。 (This function can expand the specified contract, specified event, etc. according to the actual situation to obtain the resolution operation)。
Note: The general JSON RPC API is relatively simple and does not encapsulate the corresponding DTO entity. During operation, you can use online JSON to generate entities for business integration。
State Secret Usage Instructions¶
Configure IsSMCrypt = true in the BaseConfig.cs file;Adopt state secret signature and supporting communication。
Configure DefaultPrivateKeyPemPath as the default user private key pem file in the BaseConfig.cs file [Optional]。
Generate information such as national secret user accounts, import webase-front, and view unit tests。
/// <summary> / / / Generate a pair of public and private keys. The generated json can be copied to a txt file and directly imported into components such as webase front /// </summary> [Fact] public void GMGeneratorAccountJsonTest() { var account = AccountUtils.GMGeneratorAccount("adminUser" + new Random().Next(100000, 1000000).ToString()); var accountString = account.ToJson(); // Debug.WriteLine(accountString); _testOutput.WriteLine(accountString); Assert.True(accountString.ToObject<AccountDto>().PublicKey.Length > 0); }Perform contract deployment, trading, etc., and view unit test GMContractTest.cs。
/// <summary> / / / Call the contract method asynchronously. This test calls the contract set method, which can parse input and event / / / If the transaction hash is empty, the production environment uses a scheduled service or queue to obtain the transaction hash before obtaining the corresponding data /// </summary> /// <returns></returns> [Fact] public async Task SendTranscationWithReceiptDecodeAsyncTest() { var contractService = new ContractService(BaseConfig.DefaultUrl, BaseConfig.DefaultRpcId, BaseConfig.DefaultChainId, BaseConfig.DefaultGroupId, privateKey); string contractAddress = "0x26cf8fcb783bbcc7b320a46b0d1dfff5fbb27feb";/ / Test the deployment contract above to get the contract address var inputsParameters = new[] { BuildParams.CreateParam("string", "n") }; var paramsValue = new object[] { "123" }; string functionName = "set";/ / Call contract method ReceiptResultDto receiptResultDto = await contractService.SendTranscationWithReceiptAsync(abi, contractAddress, functionName, inputsParameters, paramsValue); Assert.NotEmpty(receiptResultDto.Output); Assert.NotEmpty(receiptResultDto.Input); Assert.NotEmpty(receiptResultDto.Logs); var solidityAbi = new SolidityABI(abi); var inputList = solidityAbi.InputDecode(functionName, receiptResultDto.Input); Assert.True(inputList[0].Parameter.Name == "n" && inputList[0].Result.ToString() == "123"); string eventName = "SetEvent"; var eventList = solidityAbi.EventDecode(eventName, receiptResultDto.Logs); var eventpramas1 = eventList[0].Event.Find(x => x.Parameter.Name == "paramsStr"); var eventpramas2 = eventList[0].Event.Find(x => x.Parameter.Name == "operationTimeStamp"); Assert.True(eventpramas1.Result.ToString() == "123"); Assert.NotNull(eventpramas2.Result); }Check the relevant source code for details about the generation, signature, encryption, sending transaction, etc. of the national secret account, as well as the video of the supporting station B。
Added features¶
Add mnemonic and wallet modules
Add BIP 32, EIP 55 and other features
Optimize the acquisition of transaction receipts
Add the thread pool to pull the specified block transaction, add the Redis subscription publication
State Secret Support