Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Estimation Gas from sendTransactions array #271

Closed
quan612 opened this issue Aug 21, 2024 · 1 comment
Closed

Question: Estimation Gas from sendTransactions array #271

quan612 opened this issue Aug 21, 2024 · 1 comment

Comments

@quan612
Copy link

quan612 commented Aug 21, 2024

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,
                },
            });

@plusminushalf
Copy link
Contributor

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"
                    }
                ])
            }
        }))
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants