Help & Support

ERC20 Approval on Actions

When an action needs to spend ERC20 tokens from Signer, the Signer must first approve the ERC20 token transfer.

If the required approval is missing, the system returns a SignerErc20ApprovalRequired error that indicates which token needs approval before the action can proceed.

1

Prepare Approval Transaction

Approval for a given Signer/Token pair for an authenticated Account can be prepared in two ways:

  • Infinite Approval - approve unlimited amount of tokens (only once per token).

  • Exact Approval - approve a specific amount of tokens to spend.

Use the prepareSignerErc20Approval action to prepare an approval transaction.

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

2

Handle Result

Then, handle the result using the adapter for the library of your choice:

import { handleOperationWith } from "@lens-protocol/client/viem";
// …
const result = await prepareSignerErc20Approval(sessionClient, {  approval: {    infinite: evmAddress("0x1234…"),  },}).andThen(handleOperationWith(walletClient));

See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.

3

Retry the operation

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