"use client"; import { Button, notification, ConfigProvider } from "antd"; import { useCallback, useState } from "react"; import { SignerInterface, TransactionReceipt } from "koilib"; import theme from "./theme"; import styles from "./page.module.css"; import { KoinosForm, prettyName } from "../components/KoinosForm"; import { ProjectDescription } from "@/components/ProjectDescription"; import { HeaderComponent } from "@/components/HeaderComponent"; import { FooterComponent } from "@/components/FooterComponent"; import { contract, readContract, writeContract } from "@/koinos/contract"; import { BLOCK_EXPLORER } from "@/koinos/constants"; export default function Home() { const [selectedMethod, setSelectedMethod] = useState(""); const [submitText, setSubmitText] = useState(""); const [args, setArgs] = useState({}); const [signer, setSigner] = useState(undefined); const [code, setCode] = useState(""); const [loading, setLoading] = useState(false); const [results, setResults] = useState(""); const submit = useCallback(async () => { try { setLoading(true); setResults(""); let textArgs = JSON.stringify(args, null, 2); const { read_only: readOnly } = contract.abi!.methods[selectedMethod]; if (readOnly) { if (textArgs === "{}") textArgs = ""; setCode( `const { result } = await contract.functions.${selectedMethod}(${textArgs});`, ); const res = await readContract(selectedMethod, args); setResults(`result:\n\n${JSON.stringify(res, null, 2)}`); } else { if (!signer) throw new Error("Connect wallet"); setCode(`const { transaction, receipt } = await contract.functions.${selectedMethod}(${textArgs},{ rcLimit: 10_00000000, // 10 mana });`); const onTxSubmit = (receipt?: TransactionReceipt) => { notification.success({ message: "Transaction submitted", description: "the transaction is in the mempool waiting to be mined", placement: "bottomLeft", duration: 15, }); setResults(`receipt:\n\n${JSON.stringify(receipt, null, 2)}`); }; const { transaction } = await writeContract( selectedMethod, args, signer, onTxSubmit, ); notification.success({ message: "Transaction mined", description: ( see confirmation in{" "} {" "} koinosblocks{" "} {" "} ), placement: "bottomLeft", duration: 15, }); } setLoading(false); } catch (error) { notification.error({ message: (error as Error).message, placement: "bottomLeft", duration: 15, }); setLoading(false); } }, [args, signer, contract, selectedMethod]); const contractMethods = Object.keys(contract.abi!.methods).map((name) => { return { name, prettyName: prettyName(name), readOnly: contract.abi!.methods[name].read_only, }; }); return (
setSigner(s)}>

Select Function

{contractMethods.map((contractMethod) => ( ))}
{selectedMethod ? (

{prettyName(selectedMethod)}

{contract.abi!.methods[selectedMethod].description}

setArgs(newArgs)} > {signer && !contract.abi!.methods[selectedMethod].read_only ? (
Sign as {signer.getAddress()}
) : null} {code ?
{code}
: null} {results ?
{results}
: null}
) : null}
); }