Untitled

 avatar
unknown
typescript
a year ago
2.1 kB
6
Indexable
import Wallet, { BitcoinNetworkType } from "sats-connect";

interface RunesEtchOptions {
  runeName: string;
  divisibility?: number;
  isMintable: boolean;
  destinationAddress: string;
  feeRate: number;
  refundAddress: string;
  network: BitcoinNetworkType;
  premine?: string;
  symbol?: string;
  terms?: {
    amount?: string;
    cap?: string;
    heightStart?: string;
    heightEnd?: string; 
    offsetStart?: string; 
    offsetEnd?: string; 
  };
  inscriptionDetails?: {
    contentType: string;
    contentBase64: string;
    delegateInscriptionId?: string;
  };
  appServiceFee?: number;
  appServiceFeeAddress?: string;
}

const etchRunes = async (
  options: RunesEtchOptions,
  callback: (result: {
    state: string;
    message: string;
    orderId?: string;
    fundTransactionId?: string;
  }) => void
) => {
  try {
    // Prepare the payload for the runes etch method
    const payload = {
      runeName: options.runeName,
      divisibility: options.divisibility,
      isMintable: options.isMintable,
      destinationAddress: options.destinationAddress,
      feeRate: options.feeRate,
      refundAddress: options.refundAddress,
      network: options.network,
      premine: options.premine,
      symbol: options.symbol,
      terms: options.terms,
      inscriptionDetails: options.inscriptionDetails,
      appServiceFee: options.appServiceFee,
      appServiceFeeAddress: options.appServiceFeeAddress,
    };

    const response = await Wallet.request("runes_etch", payload);

    if (response.status === "success") {
      callback({
        state: "success",
        message: "Runes etching initiated successfully.",
        orderId: response.result.orderId,
        fundTransactionId: response.result.fundTransactionId,
      });
    } else {
      callback({
        state: "error",
        message: "Error etching runes. " + response.error,
      });
    }
  } catch (error: any) {
    callback({
      state: "error",
      message: "Exception in etching runes: " + error.message,
    });
  }
};

export default etchRunes;
Editor is loading...
Leave a Comment