Help & Support

ERC20 Approval on Actions

Actions that spend Signer funds require ERC20 approval.

When executing action, a custom error SignerErc20ApprovalRequired can be returned which specifies that approval is required for a given token before action can be executed.

1

Prepare Approval Transaction

Approval is only required once for a given Signer/Token pair for authenticated in Account.

import { blockchainData, evmAddress, postId } from "@lens-protocol/client";import { executePostAction } from "@lens-protocol/client/actions";
const result = await prepareSignerErc20Approval(sessionClient, {  approval: {    inifinite: evmAddress("0x1234…"),  }});
if (result.isErr()) {  return console.error(result.error);}

2

Send Transaction

As a reponse from prepare request you should recieve transaction request that should send via the user's wallet (SponsoredTransactionRequest or SelfFundedTransactionRequest).

import { sendEip712Transaction, sendTransaction } from "viem/zksync";
import { walletClient } from "./viem";
if (result.isErr()) {  return console.error("Transaction failed:", result.error);}
switch (result.value.__typename) {  case "SponsoredTransactionRequest":    const hash = await sendEip712Transaction(walletClient, {      data: result.value.raw.data,      gas: BigInt(result.value.raw.gasLimit),      maxFeePerGas: BigInt(result.value.raw.maxFeePerGas),      maxPriorityFeePerGas: BigInt(result.value.raw.maxPriorityFeePerGas),      nonce: result.value.raw.nonce,      paymaster: result.value.raw.customData.paymasterParams?.paymaster,      paymasterInput:        result.value.raw.customData.paymasterParams?.paymasterInput,      to: result.value.raw.to,      value: BigInt(result.value.raw.value),    });    break;
  case "SelfFundedTransactionRequest":    const hash = await sendTransaction(walletClient, {      data: result.value.raw.data,      gas: BigInt(result.value.raw.gasLimit),      maxFeePerGas: BigInt(result.value.raw.maxFeePerGas),      maxPriorityFeePerGas: BigInt(result.value.raw.maxPriorityFeePerGas),      nonce: result.value.raw.nonce,      to: result.value.raw.to,      type: "eip1559",      value: BigInt(result.value.raw.value),    });    break;
  default:    console.error("Failed to prepare ERC20 approval request due to:", result.value.reason);}

3

Wait for Transaction

viem
import { sendEip712Transaction, sendTransaction } from "viem/zksync/actions";import { walletClient } from "./viem";
await waitForTransactionReceipt(walletClient, {  hash})
ethers
// coming soon

4

Retry the operation

Once the approval transaction has been successfully completed, re-execute the operation that required ERC20 approval.