(async () => {
  try {
    // Paste your actual signed order components and signature here:
    const orderComponents = {
      offerer: "0xb0077b904f9f5c9009fd2b90d2643cf9e1632ab4",
      zone: "0x0000000000000000000000000000000000000000",
      offer: [
        {
          itemType: 2,
          token: "0xb99dc2f1ba4e9f152c1aadaac62c185b7305e019",
          identifierOrCriteria: "1",
          startAmount: "1",
          endAmount: "1",
        },
      ],
      consideration: [
        {
          itemType: 0,
          token: "0x0000000000000000000000000000000000000000",
          identifierOrCriteria: "0",
          startAmount: "9999900000000000",
          endAmount: "9999900000000000",
          recipient: "0xb0077b904f9f5c9009fd2b90d2643cf9e1632ab4",
        },
        {
          itemType: 0,
          token: "0x0000000000000000000000000000000000000000",
          identifierOrCriteria: "0",
          startAmount: "100000000000000",
          endAmount: "100000000000000",
          recipient: "0x0000a26b00c1f0df003000390027140000faa719",
        },
      ],
      orderType: 0,
      startTime: "0",
      endTime: "2147483647",
      zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
      salt: "74197684883111492749564816983217742256264303605447043303604716134516718968043",
      conduitKey: "0x0000000000000000000000000000000000000000000000000000000000000000",
      counter: "453570546014191316910406221913189842627",
    };

    // Paste your signature (from the listing/signing phase)
    const signature = "0x276aca82bc13deff84640041c95916595084855aa994f30b5187588f9d0e47643d75280d4096c471b7a9470e9623853595d81e7679a6248069e286de5456d3ec1b";

    // Validate presence
    if (!signature || signature.length < 10) {
      alert("Please provide a valid signature string.");
      return;
    }

    // Load ethers if needed
    if (typeof ethers === "undefined") {
      await new Promise((resolve, reject) => {
        const script = document.createElement("script");
        script.src = "https://cdn.jsdelivr.net/npm/ethers@5.7.2/dist/ethers.umd.min.js";
        script.async = true;
        script.onload = () => (typeof ethers !== "undefined" ? resolve() : reject());
        script.onerror = reject;
        document.head.appendChild(script);
      });
    }

    // Provider and Signer (buyer)
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    await provider.send("eth_requestAccounts", []);
    const signer = provider.getSigner();
    const buyerAddress = await signer.getAddress();

    // Checksum utility
    const checksum = (addr) => ethers.utils.getAddress(addr);

    // Seaport contract address (Seaport v1.5)
    const SEAPORT_ADDRESS = checksum("0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC");

    // Minimal ABI needed
    const SEAPORT_ABI = [
      {
        name: "fulfillAdvancedOrder",
        type: "function",
        stateMutability: "payable",
        inputs: [
          {
            components: [
              {
                components: [
                  { name: "offerer", type: "address" },
                  { name: "zone", type: "address" },
                  {
                    components: [
                      { name: "itemType", type: "uint8" },
                      { name: "token", type: "address" },
                      { name: "identifierOrCriteria", type: "uint256" },
                      { name: "startAmount", type: "uint256" },
                      { name: "endAmount", type: "uint256" },
                    ],
                    name: "offer",
                    type: "tuple[]",
                  },
                  {
                    components: [
                      { name: "itemType", type: "uint8" },
                      { name: "token", type: "address" },
                      { name: "identifierOrCriteria", type: "uint256" },
                      { name: "startAmount", type: "uint256" },
                      { name: "endAmount", type: "uint256" },
                      { name: "recipient", type: "address" },
                    ],
                    name: "consideration",
                    type: "tuple[]",
                  },
                  { name: "orderType", type: "uint8" },
                  { name: "startTime", type: "uint256" },
                  { name: "endTime", type: "uint256" },
                  { name: "zoneHash", type: "bytes32" },
                  { name: "salt", type: "uint256" },
                  { name: "conduitKey", type: "bytes32" },
                  { name: "totalOriginalConsiderationItems", type: "uint256" },
                ],
                name: "parameters",
                type: "tuple",
              },
              { name: "numerator", type: "uint120" },
              { name: "denominator", type: "uint120" },
              { name: "signature", type: "bytes" },
              { name: "extraData", type: "bytes" },
            ],
            outputs: [{ name: "fulfilled", type: "bool" }],
          },
          {
            components: [
              { name: "orderIndex", type: "uint256" },
              { name: "side", type: "uint8" },
              { name: "index", type: "uint256" },
              { name: "identifier", type: "uint256" },
              { name: "criteriaProof", type: "bytes32[]" },
            ],
            name: "criteriaResolvers",
            type: "tuple[]",
          },
          { name: "fulfillerConduitKey", type: "bytes32" },
          { name: "recipient", type: "address" },
        ],
      },
    ];

    const seaport = new ethers.Contract(SEAPORT_ADDRESS, SEAPORT_ABI, signer);

    // Prepare advancedOrder parameter
    const advancedOrder = {
      parameters: {
        offerer: checksum(orderComponents.offerer),
        zone: checksum(orderComponents.zone),
        offer: orderComponents.offer.map((o) => ({
          itemType: o.itemType,
          token: checksum(o.token),
          identifierOrCriteria: o.identifierOrCriteria,
          startAmount: o.startAmount,
          endAmount: o.endAmount,
        })),
        consideration: orderComponents.consideration.map((c) => ({
          itemType: c.itemType,
          token: checksum(c.token),
          identifierOrCriteria: c.identifierOrCriteria,
          startAmount: c.startAmount,
          endAmount: c.endAmount,
          recipient: checksum(c.recipient),
        })),
        orderType: orderComponents.orderType,
        startTime: orderComponents.startTime,
        endTime: orderComponents.endTime,
        zoneHash: orderComponents.zoneHash,
        salt: orderComponents.salt,
        conduitKey: orderComponents.conduitKey,
        totalOriginalConsiderationItems: orderComponents.consideration.length,
      },
      numerator: 1,
      denominator: 1,
      signature: signature,
      extraData: "0x",
    };

    // No criteria resolvers
    const criteriaResolvers = [];

    // Conduit key used by fulfiller (usually 0x0)
    const fulfillerConduitKey = ethers.constants.HashZero;

    // Calculate total ETH to send (only sum consideration with itemType=0 = ETH)
    let totalETH = orderComponents.consideration.reduce((acc, item) => {
      if (item.itemType === 0) {
        return acc.add(ethers.BigNumber.from(item.startAmount));
      }
      return acc;
    }, = PLEASE REWRITE IT IN FULL VERSION BECAUSE I HAVE THIS = Uncaught SyntaxError: expected expression, got '}'