Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
/ agent-pb Public archive

An extension of @dfinity/agent to support protobufs

Notifications You must be signed in to change notification settings

ic-rocks/agent-pb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

agent-pb

An extension of @dfinity/agent to support protobufs.

Services

Service methods should include an annotation field set to query or update.

syntax = "proto3";

import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

service MyCanister {
  rpc read (google.protobuf.Empty) returns (google.protobuf.UInt64Value) {
    option annotation = query;
  };

  rpc write (google.protobuf.UInt64Value) returns (google.protobuf.Empty) {
    option annotation = update;
  };
}

Usage

First, build protobuf .json files:

IC_PATH=/ic
npx pbjs -t json -p $IC_PATH/**/*.proto my_canister.proto -o bundle.json --sparse
import extendProtobuf from "agent-pb";

const root = protobuf.Root.fromJSON(require("./bundle.json"));
const actor = Actor.createActor(/* regular args */);
extendProtobuf(actor, root.lookupService("MyCanister"));

await actor.read({});
await actor.write(5);

A complete example can be found here.

Building

npm run build

About

An extension of @dfinity/agent to support protobufs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published