Code Examples

JavaScript/TypeScript

Send Priority Message

import { ethers } from "ethers";

async function sendPriorityMessage(content, bidAmount) {
  const provider = new ethers.JsonRpcProvider("https://rpc.obsidian.network");
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

  const payload = "0x" + Buffer.from(content).toString("hex");
  const nonce = "0x" + Date.now().toString(16);
  const chainId = "0x1a5";

  // Create signature
  const messageHash = ethers.keccak256(
    ethers.solidityPacked(["bytes", "uint256", "uint256"], [payload, nonce, chainId])
  );
  const signature = await wallet.signMessage(ethers.getBytes(messageHash));

  // Send with bid
  const result = await provider.send("eth_sendMessageBlob", [
    {
      from: wallet.address,
      data: payload,
      signature,
      nonce,
      chainId,
      bid: "0x" + ethers.parseEther(bidAmount).toString(16),
    },
  ]);

  return result;
}

// Usage
const hash = await sendPriorityMessage("Important update!", "0.01");

Send Free Message (with VDF)

Fetch Messages

Check Queue Status

Python

cURL

Last updated