Skip to content

Fallback Providers

When you use ZeroDev, you can pick a specific infrastructure provider. If you don't pick one, we pick one for you.

However, sometimes an infra provider may experience downtime. We have developed a "fallbacks" feature that allows you to set up multiple providers, so that when one 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),
    middleware: {
        sponsorUserOperation: async ({ userOperation }) => {
            const zeroDevPaymasterClient = createZeroDevPaymasterClient({
                chain,
                transport: http(PAYMASTER_RPC_ALCHEMY),
                entryPoint
            })
            return zeroDevPaymasterClient.sponsorUserOperation({
                userOperation,
                entryPoint
            })
        }
    },
    entryPoint
})
 
// Create an account client with pimlico as provider
const kernelClient2 = createKernelAccountClient({
    account,
    chain,
    bundlerTransport: http(BUNDLER_RPC_PIMLICO),
    middleware: {
        sponsorUserOperation: async ({ userOperation }) => {
            const zeroDevPaymasterClient = createZeroDevPaymasterClient({
                chain,
                transport: http(PAYMASTER_RPC_PIMLICO),
                entryPoint
            })
            return zeroDevPaymasterClient.sponsorUserOperation({
                userOperation,
                entryPoint
            })
        }
    },
    entryPoint
})

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,
])