Skip to content
LogoLogo

Examples

These examples follow the V2 address-native model.

Protocol writes with @makechain/viem

import { createPublicClient, http } from "viem";
import { createEd25519Signer, makechainActions } from "@makechain/viem";
 
const signer = createEd25519Signer("0x<32-byte-ed25519-private-key>");
 
const client = createPublicClient({ transport: http() }).extend(
  makechainActions({
    gatewayUrl: "https://api.makechain.net",
    network: "testnet",
    ownerAddress: "0x0000000000000000000000000000000000000001",
    signer,
  }),
);
 
await client.projects.create({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  signer,
  name: "my-project",
  visibility: "public",
});

Verification example

await client.verification.add({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  signer,
  verificationType: "eth_address",
  address: "0x0000000000000000000000000000000000000001",
  claimSignature: "0x<claim-signature>",
});

Lifted registration flow

const rent = await client.identity.rentStorage({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  walletClient,
  publicClient,
  units: 1,
});
 
console.log(rent.claimStatus); // "pending_relayer"
 
const registration = await client.identity.waitForStorageClaim({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  timeoutMs: 120_000,
});
 
if (registration.stage === "ready_for_username") {
  await client.identity.usernameCreate({
    ownerAddress: "0x0000000000000000000000000000000000000001",
    signer,
    username: "alice",
  });
}

Commit and ref example

await client.commits.submitBundle({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  signer,
  projectId: "<64-char-project-id-hex>",
  commits: [
    {
      hash: "<64-char-commit-hash>",
      treeRoot: "<64-char-tree-root>",
      authorAddress: "0x0000000000000000000000000000000000000001",
      authorTimestamp: Math.floor(Date.now() / 1000),
      title: "feat: first commit",
      messageHash: "<64-char-message-hash>",
    },
  ],
});
 
await client.commits.updateRef({
  ownerAddress: "0x0000000000000000000000000000000000000001",
  signer,
  projectId: "<64-char-project-id-hex>",
  refName: "refs/heads/main",
  newHash: "<64-char-commit-hash>",
  nonce: 1n,
});

Read-side note

Gateway read routes in the active V2 stack are owner-address-native. Use RPC reference for the canonical request and response field names.

Merge request example

Merge request reads use the viem client (REST gateway), while writes use the SDK (message construction and signing).

Read merge requests with the viem client:

// List merge requests targeting a project
const mrs = await client.mergeRequests.list({
  projectId: "<64-char-project-id-hex>",
});
 
// Get a specific merge request
const mr = await client.mergeRequests.get({
  projectId: "<64-char-project-id-hex>",
  requestId: "<64-char-request-id-hex>",
});
 
// List merge requests opened by an account
const myMrs = await client.mergeRequests.listByRequester({
  ownerAddress: "0x0000000000000000000000000000000000000001",
});

Write merge requests with the SDK:

import { createClient } from "@makechain/sdk";
 
const client = createClient({
  endpoint: "https://api.makechain.net",
  network: "testnet",
});
 
// Open a merge request from a fork
await client.mergeRequestAdd(keypair, ownerAddress, {
  projectId: "<upstream-project-id>",
  sourceProjectId: "<fork-project-id>",
  sourceRef: "refs/heads/feature",
  sourceCommitHash: "<64-char-commit-hash>",
  targetRef: "refs/heads/main",
  title: "Add new feature",
});
 
// Close a merge request (requester withdrawal or maintainer closure)
await client.mergeRequestRemove(keypair, ownerAddress, {
  projectId: "<upstream-project-id>",
  requestId: "<64-char-request-id>",
});