Send your first transaction with ERC-20 Paymaster | Web3Auth

A paymaster is a vital component in the ERC-4337 standard, responsible for covering transaction costs on behalf of the user. There are various types of paymasters, such as gasless paymasters, ERC-20 paymasters, and more.


This is a companion discussion topic for the original entry at https://web3auth.io/docs/guides/erc20-paymaster

Hello,

I tried exactly your tutorial but it does not work
I created a new project from the quickstart then follow this for send usdc and got the following error :
Unhandled Promise Rejection: UserOperationExecutionError: Paymaster postOp function reverted.

and on Pimlico I see this error

{
“id”: 12,
“error”: {
“code”: -32521,
“message”: “UserOperation reverted during simulation with reason: AA50 postOp reverted 0x7939f424”
},
“jsonrpc”: “2.0”
}

I have generated a debug link on tenderly

I am stuck on this for a few months and losing my hair. Could you help me ?

Thanks,

Pratik

Hey @pratikraj.bhavsar can you please share the code for AccountAbstractionProvider. We’ll need more details to debug the issue.

//Blockquote
const accountAbstractionProvider = new AccountAbstractionProvider({
config: {
chainConfig,
bundlerConfig: {
// Get the pimlico API Key from dashboard.pimlico.io
url: https://api.pimlico.io/v2/${chainId}/rpc?apikey=${pimlicoAPIKey},
paymasterContext: {
// USDC address on Ethereum Sepolia
token: “0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238”,
},
},
smartAccountInit: new SafeSmartAccount(),
paymasterConfig: {
// Get the pimlico API Key from dashboard.pimlico.io
url: https://api.pimlico.io/v2/${chainId}/rpc?apikey=${pimlicoAPIKey},
},
},
});

//Blockquote
// IMP START - SDK Initialization
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig },
});

//Blockquote
const web3AuthOptions: Web3AuthOptions = {
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
privateKeyProvider,
// Use the account abstraction provider we configured earlier
accountAbstractionProvider,
// This will allow you to use EthereumPrivateKeyProvider for
// external wallets, while use the AccountAbstractionProvider
// for Web3Auth embedded wallets.
useAAWithExternalWallet: false,
};
const web3auth = new Web3Auth(web3AuthOptions);

then I send the transaction

// Use the same accountAbstractionProvider we created earlier.
const bundlerClient = accountAbstractionProvider.bundlerClient!;
const smartAccount = accountAbstractionProvider.smartAccount!;

// Pimlico’s ERC-20 Paymaster address
const pimlicoPaymasterAddress = “0x0000000000000039cd5e8aE05257CE51C473ddd1”;

// USDC address on Ethereum Sepolia
const usdcAddress = “0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238”;

// 0.00001 ETH in WEI format
const amount = 10000000000000n;

// 10 USDC in WEI format. Since USDC has 6 decimals, 10 * 10^6
const approvalAmount = 1000000n;

const userOpHash = await bundlerClient.sendUserOperation({
account: smartAccount,
calls: [
// Approve USDC on Sepolia chain for Pimlico’s ERC 20 Paymaster
{
to: usdcAddress,
abi: parseAbi([“function approve(address,uint)”]),
functionName: “approve”,
args: [pimlicoPaymasterAddress, approvalAmount],
},
{
to: “0xf63d71b8E48AAdbdcf49bfF0CB849eC98efc4849”,
value: amount,
data: “0x”,
},
{
to: “0xf63d71b8E48AAdbdcf49bfF0CB849eC98efc4849”,
value: amount,
data: “0x”,
},
],
});

// Retrieve user operation receipt
const receipt = await bundlerClient.waitForUserOperationReceipt({
hash: userOpHash,
});

Looks like Pimlico’s paymaster address is changed, can you change the pimlicoPaymasterAddress to 0x777777777777AeC03fd955926DbF81597e66834C and try once?

Hello,

it’s working thank you very much.

I am trying to send 1 USDC

Could you tell me what value should I put in

const amount = ?;
// 10 USDC in WEI format. Since USDC has 6 decimals, 10 * 10^6
const approvalAmount = ?;

Regards,

Pratik