pimlicolabs/permissionless.js

Question: Estimation Gas from sendTransactions array

Closed this issue · 1 comments

Hi,

I am new to pimlico and permissionless

I have a working code when we need to bulk transfer out some NFTs from a smart account into a destination wallet, using sendTransactions()

https://docs.pimlico.io/permissionless/reference/smart-account-actions/sendTransactions

Wondering how to estimate the gas for these bulk transfers?

working code:

const transactions: {
    to: Address;
    data: Hex;
}[] = [];

selectedNfts.map((nft) => {
    transactions.push({
        to: NFT_CONTRACT_ADDRESS,
        data: encodeFunctionData({
            abi: contractAbi,
            functionName: "safeTransferFrom",
            args: [
                smartAccountAddress,
                destinationWallet as `0x${string}`,
                BigInt(nft.tokenId),
            ],
        }),
    });
});

then

const transactionHash = await smartAccountClient.sendTransactions({
    transactions: transactions,
});

I saw this https://docs.pimlico.io/permissionless/reference/bundler-actions/estimateUserOperationGas but feel like its for single transaction

permissionless: 0.1.44
entry_point: v07

code that setup smartAccountClient:


const safeAccount = await signerToSafeSmartAccount(publicClient, {
                signer: customSigner,
                safeVersion: "1.4.1",
                entryPoint: ENTRYPOINT_ADDRESS_V07,
            });
            
            const pimlicoPaymaster = createPimlicoPaymasterClient({
                chain: networkToUse,

                transport: http(process.env.NEXT_PUBLIC_PIMLICO_PAYMASTER_URL),
                entryPoint: ENTRYPOINT_ADDRESS_V07,
            });

            const pimlicoBundler = createPimlicoBundlerClient({
                transport: http(process.env.NEXT_PUBLIC_PIMLICO_PAYMASTER_URL),
                entryPoint: ENTRYPOINT_ADDRESS_V07,
            });

const smartAccountClient = createSmartAccountClient({
                account: safeAccount,
                entryPoint: ENTRYPOINT_ADDRESS_V07,
                chain: networkToUse,
                bundlerTransport: http(process.env.NEXT_PUBLIC_PIMLICO_PAYMASTER_URL),
                middleware: {
                    sponsorUserOperation: pimlicoPaymaster.sponsorUserOperation,
                    gasPrice: async () => (await pimlicoBundler.getUserOperationGasPrice()).fast,
                },
            });

You can estimate using estimateUserOperationGas

bundlerClient.estimateUserOperationGas({
    userOperation: {
        ...(await smartAccountClient.prepareUserOperationRequest({
            userOperation: {
                callData: await smartAccount.encodeCallData([
                    {
                        to: zeroAddress,
                        value: 0n,
                        data: "0x"
                    },
                    {
                        to: zeroAddress,
                        value: 0n,
                        data: "0x"
                    }
                ])
            }
        }))
    }
})