React SDK

useRegisterCommitments

Register blob commitments on-chain

This mutation registers blob commitments (merkle roots) on the Aptos blockchain as part of the blob upload process. It supports both account signers and wallet adapter signers, and handles batch registration of multiple blobs.

Examples

Account Signer

import { Account } from "@aptos-labs/ts-sdk";
import { useRegisterCommitments } from "@shelby-protocol/react";

function RegisterCommitments() {
  const { mutateAsync: encodeBlobs } = useEncodeBlobs({
    onSuccess: (commitments) => {
      console.log("Encoded", commitments.length, "blobs");
    },
  });

  const registerCommitments = useRegisterCommitments({
    onSuccess: ({ hash }) => {
      console.log("Transaction hash:", hash);
    },
  });

  const handleRegister = async () => {
    const blobCommitments = await encodeBlobs({ blobs: [{ 
      blobName: "file1.txt",
      blobData: new Uint8Array([...])
    }],
  });

    const signer = Account.generate();
    const commitments = [
      {
        blobName: "file1.txt",
        commitment: blobCommitments[0],
      },
    ];

    registerCommitments.mutate({
      signer,
      commitments,
      expirationMicros: Date.now() * 1000 + 86400000000, // 1 day
    });
  };

  return (
    <button onClick={handleRegister} disabled={registerCommitments.isPending}>
      {registerCommitments.isPending ? "Registering..." : "Register Commitments"}
    </button>
  );
}

Wallet Adapter

import { useRegisterCommitments } from "@shelby-protocol/react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";

function RegisterCommitmentsWithWallet() {
  const { mutateAsync: encodeBlobs } = useEncodeBlobs({
    onSuccess: (commitments) => {
      console.log("Encoded", commitments.length, "blobs");
    },
  });

  const { account, signAndSubmitTransaction } = useWallet();
  const registerCommitments = useRegisterCommitments();

  const handleRegister = async () => {
    if (!account || !signAndSubmitTransaction) {
      alert("Please connect your wallet");
      return;
    }

    const blobCommitments = await encodeBlobs({ blobs: [{ 
      blobName: "file1.txt",
      blobData: new Uint8Array([...])
    }] });

    registerCommitments.mutate({
      signer: { account: account.accountAddress, signAndSubmitTransaction },
      commitments: [
        {
          blobName: "file1.txt",
          commitment: blobCommitments[0],
        },
      ],
      expirationMicros: Date.now() * 1000 + 86400000000,
    });
  };

  return (
    <button onClick={handleRegister} disabled={registerCommitments.isPending}>
      Register Commitments
    </button>
  );
}

Parameters

Prop

Type

React Query Options

Prop

Type

Mutation Variables

Prop

Type

Return Value

Prop

Type