import { MiniKit } from "@worldcoin/minikit-js";
import {
Tokens,
tokenToDecimals,
type CommandResultByVia,
type MiniKitPayOptions,
type PayResult,
} from "@worldcoin/minikit-js/commands";
export async function sendPayment() {
// Create a nonce in the backend to use as a reference for this payment.
const response = await fetch("/api/generate-nonce", { method: "POST" });
const { id } = await response.json();
const input = {
reference: id,
to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
tokens: [
{
symbol: Tokens.WLD,
token_amount: tokenToDecimals(1, Tokens.WLD).toString(),
},
],
description: "Example payment",
fallback: () => {
alert("Please complete the payment in World App to proceed.");
},
};
const result: CommandResultByVia<PayResult, PayResult, "minikit"> =
await MiniKit.pay(input);
await fetch("/api/confirm-payment", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(result.data),
});
}