{"id":23888379,"url":"https://github.com/edjcase/icp.net","last_synced_at":"2025-04-04T19:10:37.108Z","repository":{"id":63871045,"uuid":"476344137","full_name":"edjCase/ICP.NET","owner":"edjCase","description":"A library for .NET/C#/Unity to natively communicate with the Internet Computer (ICP)","archived":false,"fork":false,"pushed_at":"2025-02-04T15:13:40.000Z","size":145140,"stargazers_count":53,"open_issues_count":4,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-06T09:13:52.003Z","etag":null,"topics":["csharp","dfinity","internet-computer","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edjCase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-31T14:32:45.000Z","updated_at":"2025-02-04T15:12:24.000Z","dependencies_parsed_at":"2023-07-13T07:10:24.656Z","dependency_job_id":"e4d11d89-983c-4a61-8721-6beb94b9a884","html_url":"https://github.com/edjCase/ICP.NET","commit_stats":null,"previous_names":["edjcase/icp.net"],"tags_count":121,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2FICP.NET","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2FICP.NET/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2FICP.NET/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2FICP.NET/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edjCase","download_url":"https://codeload.github.com/edjCase/ICP.NET/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234921,"owners_count":20905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dfinity","internet-computer","unity"],"created_at":"2025-01-04T08:47:28.042Z","updated_at":"2025-04-04T19:10:37.081Z","avatar_url":"https://github.com/edjCase.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ICP.NET\n\nCollection of Internet Computer Protocol (ICP) libraries for .NET/Blazor/Unity\n\n- [Agent](src/Agent/README.md) - Library to communicate to and from the Internet Computer\n\n- [Candid](src/Candid/README.md) - Library of Candid Encoding, Models and Helpers\n\n- [Client Generator](src/ClientGenerator/README.md) - Client source code generator for ICP canisters\n\n- [PocketIC](src/PocketIC/README.md) - [PocketIC Server](https://github.com/dfinity/pocketic) client and runner for automating tests for canisters\n\n## See each individual project README for more in depth guides\n\n# 🎮 Unity Integration\n\n- Download latest `agent.unitypackage` from: https://github.com/edjCase/ICP.NET/releases\n- Import `agent.unitypackage` into your unity project\n- If using WebGL, follow the additional WebGL instructions in the [Agent Docs](src/Agent/README.md)\n- If generating a client (see below), place the generated files into the scripts folder: `Assets/scripts/MyClient`\n- Start coding 💻\n\n# 📡 Generating a client for a canister\n\nYou can specify all the models and api calls yourself, but this is a tool to automatically generate a client and models based on the canister or .did file\n\n- Prerequisite: Have .Net 6 installed (https://dotnet.microsoft.com/en-us/download/dotnet)\n- Navigate to directory of .Net project\n  ```\n  cd {path/to/project}\n  ```\n- Add Agent nuget package to project\n  ```\n  dotnet add package EdjCase.ICP.Agent\n  ```\n- Install ClientGenerator\n\n  ```\n  dotnet tool install -g EdjCase.ICP.ClientGenerator\n  ```\n\n  This will allow a client to be automatically be generated for a canister. See [ClientGenerator README](src/ClientGenerator/README.md) for more details and advanced config\n\n- Initialize ClientGenerator config (first run only)\n  ```\n  candid-client-generator init\n  ```\n  This will create a TOML config file in the directory that can be changed for more advanced options\n- Update created config file `candid-client.toml`\n\n  If using a canister id:\n\n  ```toml\n  namespace = \"ProjectGovernance\" # Base namespace to use\n  output-directory = \"./Clients\" # Output directory\n\n  [[clients]]\n  name = \"Governance\" # Label of client to use\n  type = \"canister\" # Indicates to make client from a canister id\n  canister-id = \"rrkah-fqaaa-aaaaa-aaaaq-cai\" # Canister id to make client for\n  ```\n\n  If using a service definition file (.did)\n\n  ```toml\n  namespace = \"ProjectGovernance\" # Base namespace to use\n  output-directory = \"./Clients\" # Output directory\n\n  [[clients]]\n  name = \"Governance\" # Label of client to use\n  type = \"file\" # Indicates to make client from a service definition file\n  file-path = \"Governance.did\" # File to use\n  ```\n\n  For all configuration options see [ClientGenerator README](src/ClientGenerator/README.md) for more details\n\n- Generate Client\n  ```\n  candid-client-generator gen\n  ```\n  Will output C# file to the output directory specified in the config\n- Use client in code\n  ```cs\n  var agent = new HttpAgent();\n  Principal canisterId = Principal.FromText(\"rrkah-fqaaa-aaaaa-aaaaq-cai\");\n  var client = new GovernanceApiClient(agent, canisterId);\n  OptionalValue\u003cSample.Shared.Governance.Models.ProposalInfo\u003e proposalInfo = await client.GetProposalInfo(110174);\n  ...\n  ```\n- SHIP IT! 🚀\n\n# Breaking change migrations\n\n## 3.x.x =\u003e 4.x.x\n\nThe big change here was around variant classes and their attributes. Before the option types were defined by the attribute on each enum member, but in 4.x.x it changed to using method return types and having not type information in attributes. Also the VariantAttribute now gets the enum type from the Tag property vs the attribute\n\n### Version 3\n\n```\n[Variant(typeof(MyVariantTag))] // Required to flag as variant and define options with enum\npublic class MyVariant\n{\n    [VariantTagProperty] // Flag for tag/enum property, not required if name is `Tag`\n    public MyVariantTag Tag { get; set; }\n    [VariantValueProperty] // Flag for value property, not required if name is `Value`\n    public object? Value { get; set; }\n}\n\npublic enum MyVariantTag\n{\n    [CandidName(\"o1\")] // Used to override name for candid\n    Option1,\n    [CandidName(\"o2\")]\n    [VariantType(typeof(string))] // Used to specify if the option has a value associated\n    Option2\n}\n```\n\n### Version 4\n\n```\n[Variant] // Required to flag as variant\npublic class MyVariant\n{\n\t[VariantTagProperty] // Flag for tag/enum property, not required if name is `Tag`\n\tpublic MyVariantTag Tag { get; set; }\n\t[VariantValueProperty] // Flag for value property, not required if name is `Value`\n\tpublic object? Value { get; set; }\n\n\n\t// This method is used to specify if the option has a type/value associated\n\t[VariantOption(\"o2\")] // Specify the candid tag if different than 'As{CandidTag}' like 'Option2' here\n\tpublic string AsOption2()\n\t{\n\t\treturn (string)this.Value!;\n\t}\n}\n\npublic enum MyVariantTag\n{\n    [CandidName(\"o1\")] // Used to override name for candid\n    Option1,\n    [CandidName(\"o2\")]\n    Option2\n}\n```\n\n# Candid Related Links\n\n- [IC Http Interface Spec](https://smartcontracts.org/docs/current/references/ic-interface-spec)\n- [Candid Spec](https://github.com/dfinity/candid/blob/master/spec/Candid.md)\n- [Candid Decoder](https://fxa77-fiaaa-aaaae-aaana-cai.raw.ic0.app/explain)\n- [Candid UI Tester](https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.ic0.app)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Ficp.net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedjcase%2Ficp.net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Ficp.net/lists"}