+
Enable and Disable Delegations
+
+ In this example, a delegation is created that is enabled by default. Its
+ status can then be changed using the provided buttons which send the
+ corresponding User Operation.
+
+
+
Note
+
+ A delegation can only be re-enabled if it is currently disabled, and
+ disabled if it is currently enabled. Attempting to set the status to
+ its existing state will result in an error."
+
+
+
+ Create "delegator" Account
+ {" "}
+
Accounts:
+
+ Delegate:{" "}
+
+
+ Delegator:{" "}
+
+
+
+
+ Create Delegation
+ {" "}
+ {delegation && (
+ <>
+
+ Sign Delegation
+
+
Delegation:
+
{formatJSON(delegation)}
+
Delegation Status:
+
+ {`The delegation is ` + (delegationStatus ? "enabled" : "disabled")}
+ .
+
+
+
+ Refresh Status
+ {" "}
+ {/* New button */}
+
+ Disable Delegation
+ {" "}
+
+ Enable Delegation
+
+
UserOpDisable:
+ {userOpExplorerUrlDisable && (
+
+ View transaction
+
+ )}
+
UserOpEnable:
+ {userOpExplorerUrlEnable && (
+
+ View transaction
+
+ )}
+ >
+ )}
+
+ );
+}
+
+export default App;
diff --git a/src/app/page.tsx b/src/app/page.tsx
index b297e64..3d7310a 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,101 +1,105 @@
"use client";
import { useState } from "react";
-import { http } from "viem";
+import { createPublicClient, http, zeroAddress } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { sepolia as chain } from "viem/chains";
import {
Implementation,
- createDeleGatorClient,
- PimlicoVerifyingPaymasterSponsor,
- PimlicoGasFeeResolver,
- createBundlerClient,
- createAction,
- type DeleGatorClient,
- UserOperationReceiptResponse,
- getExplorerAddressLink,
- getExplorerTransactionLink,
+ toMetaMaskSmartAccount,
+ type MetaMaskSmartAccount,
} from "@codefi/delegator-core-viem";
+import {
+ createBundlerClient,
+ createPaymasterClient,
+ UserOperationReceipt,
+} from "viem/account-abstraction";
+import { createPimlicoClient } from "permissionless/clients/pimlico";
const BUNDLER_URL = process.env.NEXT_PUBLIC_BUNDLER_URL!;
-const PIMLICO_PAYMASTER_KEY = process.env.NEXT_PUBLIC_PAYMASTER_API_KEY!;
+const RPC_URL = process.env.NEXT_PUBLIC_RPC_URL!;
+// if this is undefined, the API_KEY must be configured to Enable verifying paymaster
+const PAYMASTER_POLICY_ID = process.env.NEXT_PUBLIC_PAYMASTER_POLICY_ID;
import examples from "@/app/examples";
import Hero from "../components/Hero";
function App() {
- const [delegator, setDelegator] = useState