Published
Jun 1, 2022
4y ago
Total Downloads
57.0K
57,035
Install
dotnet add package EdjCase.ICP.Candid --version 0.0.1-beta.20
| Product | Versions |
|---|---|
| .NET Standard |
README
ICP.NET
Collection of Internet Computer Protocol (ICP) libraries for .NET/Blazor
Agent
- Library to communicate to and from the Internet Computer
- Nuget:
EdjCase.ICP.Agent(*currently only pre-release versions are available)
Candid
- Library of Candid Encoding, Models and Helpers
- Nuget:
EdjCase.ICP.Candid(*currently only pre-release versions are available)
Samples
- A few projects to demo the capabilities of the ICP libraries
- Blazor
- AspNetCore
- CLI
- A few projects to demo the capabilities of the ICP libraries
Roadmap/TODO
- Serialization for custom C# models
- Automatic Api Client/Model generation from Candid spec
- Infer type from value, vs specifying value + type
- DID file parsing
Agent
Usage
// Create identity
var identity = new AnonymousIdentity();
// Create http agent
IAgent agent = new HttpAgent(identity);
// Create Candid arg to send in request
CandidArg arg = CandidArg.FromCandid(
CandidValueWithType.FromValueAndType( // WIP, will reduce redundancy
CandidPrimitive.Nat64(1234),
new PrimitiveCandidTypeDefinition(CandidPrimitiveType.Nat64)
)
);
// Make request to IC
string method = "get_proposal_info";
Principal governanceCanisterId = Principal.FromText("rrkah-fqaaa-aaaaa-aaaaq-cai");
QueryResponse response = await agent.QueryAsync(governanceCanisterId, method, arg);
QueryReply reply = response.ThrowOrGetReply();
CandidArg responseArg = reply.Arg;
// Use response ...
Candid
Parse from bytes
CandidArg arg = CandidArg.FromBytes(rawCandidBytes);
Reading candid values directly
CandidArg arg = CandidArg.FromBytes(rawCandidBytes);
CandidValue firstArg = arg.Values[0];
string title = firstArg.AsRecord()["title"];
Converting candid to custom classes
(custom serialization doesn't exist yet but is on the roadmap)
CandidArg arg = CandidArg.FromBytes(rawCandidBytes);
MyObj obj = arg.Values[0].Value.AsRecord(r => new MyObj
{
Title = r["title"].AsText(),
IsGoodTitle = r["is_good_title"].AsBool()
});
public class MyObj
{
public string Title { get; set; }
public bool IsGoodTitle { get; set; }
}
Parse from Text
* DID file formats are currently not supported
string text = "record { field_1:nat64; field_2: vec nat8 }";
CandidRecordType type = CandidTextParser.Parse<CandidRecordType>(text);
Generate Text representation
var type = new CandidRecordType(new Dictionary<CandidTag, CandidType>
{
{
CandidTag.FromName("field_1"),
new CandidPrimitiveType(PrimitiveType.Nat64)
},
{
CandidTag.FromName("field_2"),
new CandidVectorType(new CandidPrimitiveType(PrimitiveType.Nat8))
}
});
string text = CandidTextGenerator.Generator(type, IndentType.Tab);
Links
Changes from Previous Version
No structural changes between v0.0.1-beta.19 and v0.0.1-beta.20.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
This version is marked prerelease. Validate its API and upgrade path before production use.No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.