Skip to content

Fallback Providers

ZeroDev aggregates multiple bundler and paymaster services to provide the highest possible reliability to our users. You can set up "fallbacks" so that when one of the services fails, another takes over.

API

Start by creating multiple account clients:

// Get these from your ZeroDev dashboard
const PAYMASTER_RPC = 'your ZeroDev paymaster RPC'
const BUNDLER_RPC = 'your ZeroDev bundler RPC'
 
const PAYMASTER_RPC_ALCHEMY = PAYMASTER_RPC + '?provider=ALCHEMY'
const BUNDLER_RPC_ALCHEMY = BUNDLER_RPC + '?provider=ALCHEMY'
 
const PAYMASTER_RPC_PIMLICO = PAYMASTER_RPC + '?provider=PIMLICO'
const BUNDLER_RPC_PIMLICO = BUNDLER_RPC + '?provider=PIMLICO'
 
// Create an account client with alchemy as provider
const kernelClient1 = createKernelAccountClient({
    account,
    chain,
    bundlerTransport: http(BUNDLER_RPC_ALCHEMY),
    client: publicClient,
    paymaster: {
        getPaymasterData: ( userOperation ) => {
            const zeroDevPaymasterClient = createZeroDevPaymasterClient({
                chain,
                transport: http(PAYMASTER_RPC_ALCHEMY),
            })
            return zeroDevPaymasterClient.sponsorUserOperation({
                userOperation,
            })
        }
    },
    userOperation: {
        estimateFeesPerGas: async ({bundlerClient}) => {
            return getUserOperationGasPrice(bundlerClient)
        }
    },
    entryPoint
})
 
// Create an account client with pimlico as provider
const kernelClient2 = createKernelAccountClient({
    account,
    chain,
    bundlerTransport: http(BUNDLER_RPC_PIMLICO),
    client: publicClient,
    paymaster: {
        getPaymasterData: ( userOperation ) => {
            const zeroDevPaymasterClient = createZeroDevPaymasterClient({
                chain,
                transport: http(PAYMASTER_RPC_PIMLICO),
            })
            return zeroDevPaymasterClient.sponsorUserOperation({
                userOperation,
            })
        }
    },
    userOperation: {
        estimateFeesPerGas: async ({bundlerClient}) => {
            return getUserOperationGasPrice(bundlerClient)
        }
    },
})

Then combine the Kernel clients with the createFallbackKernelAccountClient function:

const kernelClient = createFallbackKernelAccountClient([
    kernelClient1,
    kernelClient2,
])

Now you can use kernelClient as usual. Your kernelClient will use kernelClient1 by default, and if it runs into any issues with it, it will fallback to kernelClient2.

Using non-ZeroDev infra as fallbacks

In the previous example, we used different providers as fallbacks through ZeroDev. If you are worried that ZeroDev itself might go down, you can also sign up directly with providers like Pimlico and set them up as fallback providers.

To do that, simply:

Then combine them with createFallbackKernelAccountClient:

const kernelClient = createFallbackKernelAccountClient([
    zerodevKernelClient,
    pimlicoKernelClient,
])