Examples
Working examples using the CLI, grpcurl, JavaScript, and monitoring endpoints.
CLI workflows
Register, create, query
Start a local node:
cargo run --bin node -- --seed 1 --network devnetGenerate a keypair:
cargo run --bin cli -- keygen
# Secret: a1b2c3... (64 hex chars)
# Public: d4e5f6... (64 hex chars)Register the key and create a project:
cargo run --bin cli -- register-key --secret a1b2c3... --mid 1
cargo run --bin cli -- create-project \
--secret a1b2c3... \
--mid 1 \
--name "my-project" \
--visibility public \
--description "My first Makechain project"Query:
cargo run --bin cli -- get-project-by-name --mid 1 --name "my-project"
cargo run --bin cli -- list-projects --owner 1Other queries
cargo run --bin cli -- get-account --mid 1
cargo run --bin cli -- list-refs --project <hex-project-id>
cargo run --bin cli -- list-commits --project <hex-project-id>
cargo run --bin cli -- list-collaborators --project <hex-project-id>
cargo run --bin cli -- list-verifications --mid 1
cargo run --bin cli -- list-keys --mid 1
cargo run --bin cli -- search-projects --query "my-" --limit 10
cargo run --bin cli -- project-activity --project <hex-project-id> --limit 20Blocks and status
cargo run --bin cli -- get-block --number 42
cargo run --bin cli -- list-blocks --limit 10
cargo run --bin cli -- status
cargo run --bin cli -- stats
cargo run --bin cli -- mempool-info
gRPC with grpcurl
Server reflection is enabled, so grpcurl discovers services at runtime.
grpcurl -plaintext localhost:50051 list
grpcurl -plaintext localhost:50051 list makechain.MakechainServiceQueries
grpcurl -plaintext \
-d '{"project_id": "aabbccdd..."}' \
localhost:50051 makechain.MakechainService/GetProject
grpcurl -plaintext \
-d '{"mid": 1}' \
localhost:50051 makechain.MakechainService/GetAccount
# Pagination
grpcurl -plaintext \
-d '{"limit": 10}' \
localhost:50051 makechain.MakechainService/ListProjects
grpcurl -plaintext \
-d '{"limit": 10, "cursor": "<cursor-from-response>"}' \
localhost:50051 makechain.MakechainService/ListProjectsStreaming
# All messages
grpcurl -plaintext -d '{}' \
localhost:50051 makechain.MakechainService/SubscribeMessages
# Filter by type
grpcurl -plaintext \
-d '{"message_type": "MESSAGE_TYPE_COMMIT_BUNDLE"}' \
localhost:50051 makechain.MakechainService/SubscribeMessages
# Filter by project
grpcurl -plaintext \
-d '{"project_id": "aabbccdd..."}' \
localhost:50051 makechain.MakechainService/SubscribeMessages
JavaScript / TypeScript
The node supports grpc-web for browser clients.
Using @connectrpc/connect-web
import { createClient } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { MakechainService } from "./gen/makechain_connect";
const transport = createGrpcWebTransport({
baseUrl: "http://localhost:50051",
});
const client = createClient(MakechainService, transport);
// Get a project
const project = await client.getProject({
projectId: new Uint8Array(/* 32-byte project ID */),
});
console.log(project.name, project.visibility);
// List projects
const projects = await client.listProjects({
ownerMid: 1n,
limit: 50,
});
for (const p of projects.projects) {
console.log(p.name);
}
// Stream messages
for await (const msg of client.subscribeMessages({})) {
console.log("New message:", msg.data?.type);
}Using grpc-web directly
import { MakechainServiceClient } from "./gen/makechain_grpc_web_pb";
import { GetProjectRequest } from "./gen/makechain_pb";
const client = new MakechainServiceClient("http://localhost:50051");
const req = new GetProjectRequest();
req.setProjectId(new Uint8Array(/* 32-byte project ID */));
client.getProject(req, {}, (err, response) => {
if (err) {
console.error(err.message);
return;
}
console.log("Project:", response.getName());
});
Monitoring
Health endpoints
On the metrics port (default 9090):
curl http://localhost:9090/healthz # Liveness
curl http://localhost:9090/readyz # ReadinessPrometheus
curl http://localhost:9090/metrics
# Example output:
# makechain_messages_submitted_total{type="PROJECT_CREATE"} 42
# makechain_blocks_committed_total 1337
# makechain_mempool_size 15
# makechain_gossip_broadcast_total{outcome="success"} 500
# makechain_active_subscriptions 3