Skip to main content

Paymaster

A CandidePaymaster is a class interacts with Candide's ERC-4337 Paymaster API.

Usage

Import

import { CandidePaymaster } from "abstractionkit";

How to use

Initialize a Paymaster with your RPC url

info

Get an API key from the dashboard

paymaster.ts
import { CandidePaymaster } from "abstractionkit";

const paymasterRpc = "https://api.candide.dev/paymaster/$version/$network/$apikey";

const paymaster: CandidePaymaster = new CandidePaymaster(paymasterRPC);

Then you can consume Paymaster methods:

const paymasterMetaData = await paymaster.getPaymasterMetaData();

Methods

getPaymasterMetaData

Returns the metadata associated with the Paymaster, along with dummyPaymasterAndData useful for gas estimates

Usage

example.ts
import { paymaster } from "./paymaster";

const paymasterResult = await paymaster.getPaymasterMetaData();
Example Response
{
name: 'Candide Paymaster',
description: 'Candide Paymaster a fast, secure and feature-rich 4337 Paymaster',
icons: [],
address: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020',
sponsoredEventTopic: '0xa050a122b4c0e369e3385eb6b7cccd8019638b2764de67bec0af99130ddf8471',
dummyPaymasterAndData: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e0207ddefa2f027691116d0a7aa6418246622d70b12a0100000000ffff000000000000000000000000000000000000000000000000000000000000ffff000000000000000000000000000000000000000000000000000000000000ffff010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011c'
}

source code

getPaymasterMetaData

getSupportedERC20TokensAndPaymasterMetadata

Returns the ERC-20 Tokens that the paymaster accepts as gas tokens on the current network, along with its metadata

Usage

example.ts
import { paymaster } from "./paymaster.ts";

const result = await paymaster.getSupportedERC20TokensAndPaymasterMetadata();
Example Response
{
tokens: [
{
symbol: 'CTT',
address: '0xFa5854FBf9964330d761961F46565AB7326e5a3b',
decimal: 18,
fee: 0n,
exchangeRate: 1001219705870085130n
}
],
paymasterMetadata: {
name: 'CANDIDE Paymaster',
description: 'CANDIDE Paymaster a fast, secure and feature-rich 4337 Paymaster',
icons: [],
address: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020',
sponsoredEventTopic: '0xa050a122b4c0e369e3385eb6b7cccd8019638b2764de67bec0af99130ddf8471',
dummyPaymasterAndData: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020Fa5854FBf9964330d761961F46565AB7326e5a3b0100000000ffff000000000000000000000000000000000000000000000000000000000000ffff000000000000000000000000000000000000000000000000000000000000ffff010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011c'
}
}

Source code

getSupportedERC20TokensAndPaymasterMetadata

getSupportedEntrypoint

Returns the supported Entrypoints by the paymaster

Usage

example.ts
import { paymaster } from "./paymaster";

const paymasterResult = await paymaster.getSupportedEntrypoint();
Example Response
0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789

source code

getSupportedEntrypoint

isSupportedERC20Token

Checks if a particular ERC-20 token is accepted as gas payment by the paymaster. Returns a boolean

Usage

example.ts
import { paymaster } from "./paymaster";

const erc20TokenAddress = "0x7DdEFA2f027691116D0a7aa6418246622d70B12A";

const isSupported = await paymaster.isSupportedERC20Token(erc20TokenAddress);
Example Response
true

getSupportedERC20TokenData

Returns the token data given an erc20 address

Usage

example.ts
import { paymaster } from "./paymaster";

const erc20TokenAddress = "0xFa5854FBf9964330d761961F46565AB7326e5a3b";

const erc20TokenData = await paymaster.getSupportedERC20TokenData(erc20TokenAddress);
Details
{
symbol: 'CTT',
address: '0xFa5854FBf9964330d761961F46565AB7326e5a3b',
decimal: 18,
fee: 0n,
exchangeRate: 1001219705870085130n
}

Source code

getSupportedERC20TokenData

createPaymasterUserOperation

Estimates gas limits and set paymasterAndData. Returns a complete userOperation

Usage

import { UserOperation } from "abstractionkit";

const bundlerRPC = "https://sepolia.voltaire.candidewallet.com/rpc";

// Use the SmartAccount methods to help you construct the useroperation below
let userOperation = {
sender: '0xb8741a449d50ed0dcfe395287f85be152884c8d9',
nonce: 10n,
initCode: '0x',
callData: '0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001448d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f2009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 0n,
verificationGasLimit: 0n,
preVerificationGas: 0n,
maxFeePerGas: 66195658616n,
maxPriorityFeePerGas: 120000n,
paymasterAndData: '0x',
signature: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}

userOperation = createPaymasterUserOperation(userOperation, bundlerRPC);
Details
{
sender: '0xb8741a449d50ed0dcfe395287f85be152884c8d9',
nonce: 10n,
initCode: '0x',
callData: '0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001e48d80ff0a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000018b009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d900fa5854fbf9964330d761961f46565ab7326e5a3b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e02000000000000000000000000000000000000000000000000000a1d1b51fe47c5c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 116807n,
verificationGasLimit: 75441n,
preVerificationGas: 50444n,
maxFeePerGas: 66195658616n,
maxPriorityFeePerGas: 120000n,
paymasterAndData: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020Fa5854FBf9964330d761961F46565AB7326e5a3b00000065bcd7fc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de84cb0d94beb10a4658077bd4ad19f4fdf94425ec730f342b8115d9907f6072f40bcea6a95bce74c29b84a7d4ee9fa67f4efb39e25a2e39a2ecb110b9a0af6b6a9589bfef7ec431b',
signature: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}

Source code

createPaymasterUserOperation

createSponsorPaymasterUserOperation

Source code

createSponsorPaymasterUserOperation

createTokenPaymasterUserOperation

Estimates gas limits and set paymasterAndData for ERC-20 Token Paymaster. Returns a complete userOperation

Usage

import { SmartAccount, CandidePaymaster } from "abstractionkit";

const paymasterRPC="https://api.candide.dev/paymaster/$version/$network/$apikey";
const erc20TokenAddress = "0xFa5854FBf9964330d761961F46565AB7326e5a3b"; // CTT test token
const bundlerRPC = "https://sepolia.voltaire.candidewallet.com/rpc";
const ownerPublicAddress = "0x2Ef844456580b6e1E22e1D584EBbC2467D9298B2"

const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress])

// use smartAccount.createUserOperation to get the below
let userOperation = {
sender: '0xb8741a449d50ed0dcfe395287f85be152884c8d9',
nonce: 10n,
initCode: '0x',
callData: '0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001448d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f2009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 0n,
verificationGasLimit: 0n,
preVerificationGas: 0n,
maxFeePerGas: 66195658616n,
maxPriorityFeePerGas: 120000n,
paymasterAndData: '0x',
signature: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}

const paymaster: CandidePaymaster = new CandidePaymaster(paymasterRPC);

userOperation = await paymaster.createTokenPaymasterUserOperation(
smartAccount,
userOperation,
erc20TokenAddress,
bundlerUrl,
);
Details
{
sender: '0xb8741a449d50ed0dcfe395287f85be152884c8d9',
nonce: 10n,
initCode: '0x',
callData: '0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001e48d80ff0a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000018b009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d900fa5854fbf9964330d761961f46565ab7326e5a3b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e02000000000000000000000000000000000000000000000000000a1d1b51fe47c5c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 116807n,
verificationGasLimit: 75441n,
preVerificationGas: 50444n,
maxFeePerGas: 66195658616n,
maxPriorityFeePerGas: 120000n,
paymasterAndData: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020Fa5854FBf9964330d761961F46565AB7326e5a3b00000065bcd7fc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de84cb0d94beb10a4658077bd4ad19f4fdf94425ec730f342b8115d9907f6072f40bcea6a95bce74c29b84a7d4ee9fa67f4efb39e25a2e39a2ecb110b9a0af6b6a9589bfef7ec431b',
signature: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}

Source code

createTokenPaymasterUserOperation

calculateUserOperationErc20TokenMaxGasCost

Calculates the maximum gas cost in ERC-20 tokens for a given userOperation

Usage

import { CandidePaymaster } from "abstractionkit";

const paymasterRPC="https://api.candide.dev/paymaster/$version/$network/$apikey";
const erc20TokenAddress = "0xFa5854FBf9964330d761961F46565AB7326e5a3b"; // CTT test token

let userOperation = {
sender: '0xb8741a449d50ed0dcfe395287f85be152884c8d9',
nonce: 10n,
initCode: '0x',
callData: '0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001e48d80ff0a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000018b009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d9009a7af758ae5d7b6aae84fe4c5ba67c041dfe5336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000246a627842000000000000000000000000b8741a449d50ed0dcfe395287f85be152884c8d900fa5854fbf9964330d761961f46565ab7326e5a3b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e02000000000000000000000000000000000000000000000000000a1d1b51fe47c5c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 116807n,
verificationGasLimit: 75441n,
preVerificationGas: 50444n,
maxFeePerGas: 66195658616n,
maxPriorityFeePerGas: 120000n,
paymasterAndData: '0x3fE285DcD76BCcE4Ac92d38A6F2F8E964041e020Fa5854FBf9964330d761961F46565AB7326e5a3b00000065bcd7fc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de84cb0d94beb10a4658077bd4ad19f4fdf94425ec730f342b8115d9907f6072f40bcea6a95bce74c29b84a7d4ee9fa67f4efb39e25a2e39a2ecb110b9a0af6b6a9589bfef7ec431b',
signature: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}

const paymaster: CandidePaymaster = new CandidePaymaster(paymasterRPC);

const cost = await paymaster.calculateUserOperationErc20TokenMaxGasCost(
userOperation,
erc20TokenAddress,
);
Details
3391931975665260

Source code

calculateUserOperationErc20TokenMaxGasCost