@makechain/viem
v0.1.2
Published
Viem extension SDK for Makechain
Readme
@makechain/viem
Viem extension SDK for Makechain.
It exposes a single decorator, makechainActions(), with namespaced actions:
identityprojectscommitsaccessverificationlinksreactionssignersnodestreaming
The protocol write path is address-native in V2. Use ownerAddress for protocol message construction.
Quick Start
import { createClient, http } from "viem";
import { tempoTestnet } from "viem/chains";
import { createEd25519Signer, makechainActions } from "@makechain/viem";
const signer = createEd25519Signer("0x<32-byte-ed25519-private-key>");
const client = createClient({
chain: tempoTestnet,
transport: http(),
}).extend(
makechainActions({
gatewayUrl: "https://api.makechain.net",
network: "testnet",
ownerAddress: "0x0000000000000000000000000000000000000001",
signer,
// Optional: enforce viem client chain id at startup.
// expectedChainId: tempoTestnet.id,
http: {
timeoutMs: 15_000,
retries: 2,
retryDelayMs: 200,
retryMaxDelayMs: 2_000,
retryJitter: 0.2,
},
streaming: {
reconnect: true,
maxReconnectAttempts: Infinity,
reconnectDelayMs: 500,
reconnectMaxDelayMs: 10_000,
},
}),
);
const result = await client.projects.create({
name: "my-project",
visibility: "public",
});
console.log(result.hash, result.accepted);Protocol write examples
Project creation:
const result = await client.projects.create({
ownerAddress: "0x0000000000000000000000000000000000000001",
signer,
name: "my-project",
visibility: "public",
});Signer authorization:
const hash = client.signers.computeAddHash({
ownerAddress: "0x0000000000000000000000000000000000000001",
key: signer.publicKey,
scope: "signing",
validAfter: 1n,
validBefore: 3600n,
nonce: 0n,
allowedProjects: [],
});Protocol read examples
Read APIs are address-native in the V2 surface:
const account = await client.identity.get({
ownerAddress: "0x0000000000000000000000000000000000000001",
});
const projects = await client.projects.list({
ownerAddress: "0x0000000000000000000000000000000000000001",
});
const links = await client.links.list({
ownerAddress: "0x0000000000000000000000000000000000000001",
linkType: "follow",
});Chain/Admin Helpers
const health = await client.node.health();
const stats = await client.node.stats();
const status = await client.node.status();
const snapshot = await client.node.snapshot();
const mempool = await client.node.mempool();
console.log(
health.ready,
stats.block_height,
status.network,
snapshot.block_number,
mempool.total,
);client.node.healthBasic() is also available for the lightweight /health probe.
Streaming Helpers (SSE)
const messagesUrl = client.streaming.messagesUrl({
projectId: "<64-char-project-id-hex>",
types: [1, 20],
});
const blocksUrl = client.streaming.blocksUrl();
const messageStream = client.streaming.openMessages({
onMessage: (message) => {
console.log(message.type_name, message.hash);
},
onError: (event) => {
console.error("message stream error", event);
},
});
const blockStream = client.streaming.openBlocks({
onBlock: (block) => {
console.log(block.block_number, block.message_count);
},
onReconnect: (attempt, delayMs) => {
console.log("reconnecting blocks stream", { attempt, delayMs });
},
});
// Later
messageStream.close();
blockStream.close();If your runtime does not provide EventSource, pass an eventSourceFactory in
makechainActions({ eventSourceFactory }) or in openMessages/openBlocks options.
Protocol Write Flow Example (Commit + Ref)
await client.commits.submitBundle({
projectId: "<64-char-project-id-hex>",
contentDigest: "<64-char-content-digest-hex>",
url: "https://storage.example.com/bundle.tar.zst",
commits: [
{
hash: "<64-char-commit-hash>",
treeRoot: "<64-char-tree-root>",
title: "feat: first commit",
messageHash: "<64-char-message-hash>",
},
],
});
await client.commits.updateRef({
projectId: "<64-char-project-id-hex>",
refName: "refs/heads/main",
newHash: "<64-char-commit-hash>",
nonce: 1n,
});