Skip to content

[GENERAL] Failed to consume permission when integrating Smart Sessions module. #173

@ezhui

Description

@ezhui

Inquiry or Suggestion

❓ Summary

I’m integrating Smart Sessions with AbstractJS and ran into an error when consuming permissions.
Ref: https://docs.biconomy.io/new/smart-sessions/execute-transactions-on-users-behalf

🧪 Environment

  • abstractjs version: 1.1.18
  • Node.js version: v20.3.1
  • Network: Base

🧩 Steps to Reproduce

  1. Deployed Smart Account
  2. Installed Sessions Module
  3. Defined & granted permissions via grantPermissionTypedDataSign
  4. Tried to consume permission with usePermission

🛠 Code

  const incrementCount = async () => {
    if (!sessionDetails || !sessionSigner || !orchestrator) return;

    console.log("sessionDetails", sessionDetails);

    const toastId = toast("Executing transaction with session...", {
      autoClose: false,
    });

    try {
      const orchestratorAddress = orchestrator.addressOn(base.id)!;
      const userOwnedOrchestratorWithSessionSigner =
        await toMultichainNexusAccount({
          chainConfigurations: [
            {
              chain: base,
              transport: http(),
              version: getMEEVersion(MEEVersion.V2_1_0),
              accountAddress: orchestratorAddress, 
            },
          ],
          signer: sessionSigner,
        });

      const sessionApiKey = process.env.NEXT_PUBLIC_BICONOMY_API_KEY || getDefaultMEENetworkApiKey(false);
      const sessionMeeUrl = getDefaultMEENetworkUrl(false);
      console.log("=== Session Signer MEE Client ===");
      console.log("API Key:", sessionApiKey ? `${sessionApiKey.substring(0, 15)}...` : "undefined");
      console.log("MEE URL:", sessionMeeUrl);
      
      if (!sessionApiKey) {
        throw new Error("API key is required for session signer MEE client");
      }
      
      const sessionSignerMeeClient = await createMeeClient({
        account: userOwnedOrchestratorWithSessionSigner,
        apiKey: sessionApiKey,
        url: sessionMeeUrl, 
      });

      const sessionSignerSessionMeeClient =
        sessionSignerMeeClient.extend(meeSessionActions);

      const incrementAbiItem = getAbiItem({ abi: contractABI, name: "increment" });
      if (!incrementAbiItem || incrementAbiItem.type !== "function") {
        throw new Error("Could not find increment function in ABI");
      }
      const incrementSelector = toFunctionSelector(incrementAbiItem);

      console.log("About to use permission to execute transaction");
      const serializeBigInt = (obj: any): any => {
        if (obj === null || obj === undefined) return obj;
        if (typeof obj === 'bigint') {
          return obj.toString();
        }
        if (Array.isArray(obj)) {
          return obj.map(serializeBigInt);
        }
        if (typeof obj === 'object') {
          const serialized: any = {};
          for (const key in obj) {
            if (obj.hasOwnProperty(key)) {
              serialized[key] = serializeBigInt(obj[key]);
            }
          }
          return serialized;
        }
        return obj;
      };
      console.log("Session Details:", JSON.stringify(serializeBigInt(sessionDetails), null, 2));
      console.log("Contract Address:", CONTRACT_ADDRESS);
      console.log("Increment Selector:", incrementSelector);
      
      const executionPayload = await sessionSignerSessionMeeClient.usePermission({
        sessionDetails,
        mode: "ENABLE_AND_USE",
        instructions: [
          {
            chainId: base.id, // Base chainId = 8453
            calls: [
              {
                to: CONTRACT_ADDRESS,
                data: incrementSelector,
              },
            ],
          },
        ],
        feeToken: {
          address: "0x0000000000000000000000000000000000000000" as `0x${string}`, 
          chainId: base.id,
        },
        // verificationGasLimit: BigInt(500000000000000), // Increase verification gas
      });
      
      console.log("Execution payload:", executionPayload);

      console.log("Waiting for execution receipt, hash:", executionPayload.hash);
      const receipt = await sessionSignerMeeClient.waitForSupertransactionReceipt({
        hash: executionPayload.hash,
        mode: "fast-block", 
        confirmations: 1,
        waitForReceipts: true,
      });
      console.log("Execution receipt received:", receipt);

      setTxnHash(executionPayload.hash);

    toast.update(toastId, {
        render: "Transaction executed successfully!",
      type: "success",
      autoClose: 5000,
    });
    } catch (err: any) {
      toast.update(toastId, {
        render: `Error: ${err.message}`,
        type: "error",
        autoClose: 5000,
      });
      console.error(err);
    }
  };

🔥 Error

 POST https://network.biconomy.io/v1/exec 400 (Bad Request)
VM217 index.tsx:551 Error: FailedOpWithRevert: AA23 reverted
    at async incrementCount (VM217 index.tsx:510:38)

❗ What I Expected

Permission to be consumed and transaction to execute successfully.

🚀 Any suggestions?

Relevant Links or References

https://docs.biconomy.io/new/smart-sessions/execute-transactions-on-users-behalf

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions