EXAMPLE

Meta Mask

if (typeof window.ethereum === "undefined") {
  alert("MetaMask not installed");
  return;
}

const web3 = new Web3(window.ethereum);

const body = {
  title: "Your title",
  description: "Your description",
  token: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // USDC
  price: "1", // 1 USD, 0.1 // 1 cent
  days: "7", // 7, 31, 365
  network: "POLYGON",
};

const response = await fetch("https://api.monarchpay.com/subscriptions/create", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(body)
}

const data = await response.json();
if (data.error) {
  alert(data.error);
  return;
}
const { to, data } = data;

try {
  const recipet = await web3.eth.sendTransaction({ to, data, gas: "300000" });
  console.log(recipet.transactionHash);
} catch(e) {
  alert(e.message);
}

Last updated