Integrating `@web3auth/coinbase-adapter` with Viem's Coinbase Smart Wallet for ERC-4337 Features

How can I use @web3auth/coinbase-adapter with Viem’s Coinbase Smart Wallet (Coinbase Smart Wallet · Viem)? In their example, the owner is configured using a private key:

export const owner = privateKeyToAccount('0x...')

const account = await toCoinbaseSmartAccount({ 
  client, 
  owners: [owner], 
})

Currently, in my app, I use the Coinbase adapter as an EIP-1193 private wallet configured through the Web3Auth provider, which works fine. However, it lacks the features of an ERC-4337 smart wallet. I’d prefer to use Viem’s smart account functions instead.

const walletClient = createWalletClient({
  chain,
  transport: custom(provider), // Web3Auth provider
});

Hey Benny! :star2:

Thanks for reaching out. You’re trying to integrate the @web3auth/coinbase-adapter with Viem’s Coinbase Smart Wallet for ERC-4337, and you’re looking to utilize Viem’s smart account functions instead of the EIP-1193 private wallet setup. Let’s try to get you on the right path!

Steps to Approach:

  1. Understand Viem’s Configuration:

    • Viem’s example configures the owner using a private key.
    • You’ll aim to use Web3Auth with this setup to replace the manual private key provision.
  2. Integration Strategy:

    • Determine if Web3Auth can provide the required abstraction layer to act like the private key owner Viem expects. This might require mapping the Web3Auth provider’s functionality to work with toCoinbaseSmartAccount.
  3. Check Web3Auth Support and Available Features:

    • Verify if @web3auth/coinbase-adapter supports functionality beyond EIP-1193, like what is needed for Viem’s smart account.

Proposed Steps:

  • Bridge Web3Auth with Viem’s Configuration:
    • Try exploring ways to extract the necessary account info from Web3Auth that Viem can utilize as the owner.
    • Investigate if Web3Auth can simulate or provide an interface that mimics passing a private key as required by the Viem configuration.

Next Steps:

  • Ensure your Web3Auth and Coinbase adapter setup can be integrated or adapted to fulfill the requirements of Viem’s setup. This might involve checking if Web3Auth can use some middleware or custom method to match these prerequisites.

If you have any additional code snippets or setup details you can share, feel free! This will help refine and tackle any remaining integration challenges. :blush:

Is this information helpful for what you need to achieve? Let me know how I can assist further! :rocket:

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Hey, I checked the documentation, and you can’t use the Viem’s Coinbase Smart Wallet with Web3Auth, when you use Web3Auth account/ External Wallets the provider is JSON-RPC provider, and Viem only accepts the LocalAccount or WebAuthnAccount. Hence the example shows private key and passkey.

Documentation for the owners: Coinbase Smart Wallet · Viem

Do you specifically want to use only Coinbase Smart Wallet, or Safe, Kernel would work for you as an AA provider?

I specifically want to use the Coinbase Smart Wallet as a connection option for our application, allowing users to interact with the app via their Smart Wallet rather than as an EIP-1193 wallet. Using the Coinbase Smart Wallet as an EIP-1193 wallet eliminates the ability to sponsor transactions. Additionally, handling the Coinbase Wallet separately undermines the purpose of integrating Web3Auth into our architecture and significantly complicates the codebase. For context, we already use Safe + Pimlico for users connecting through the Google verifier on Web3Auth.

Using the EIP-1193 provider with Pimlico AA works, so I suppose that should also be doable with Coinbase Smart Wallet. For example this is my Pimlico config using Web3Auth provider:

    const safeSmartAccount = await toSafeSmartAccount({
      client: publicClient,
      owners: [provider as EIP1193Provider],
      entryPoint: {
        address: entryPoint07Address,
        version: "0.7",
      },
      version: "1.4.1",
    });

Got it, one way around is to use the JSON-RPC methods supported by the Smart Wallet directly. For instance, you can use the EIP1193Provider you get from Web3Auth, and request the specific methods.

Supported methods for the Coinbase SCW

For batch transaction and paymaster, the Coinbase smart wallet uses EIP 5792. Read more about EIP 5792.

You can use the wallet_sendCalls method to do batch transactions, also define the other capabilities supported by the wallet.

Check capabilities:

 const capabilities = provider.request({
      method: 'wallet_getCapabilities',
      params: [address[0]]
 });

console.log(capabilities);

The above will give capabilities supported for all the chains.

Send calls:

 const response = await provider.request({
      method: "wallet_sendCalls",
      params: [{
        version: '1.0',
        chainId: '0x01',
        from: address[0],
        calls: [
          {
            to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
            value: '0x9184e72a',
            data: '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
          },
          {
            to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
            value: '0x182183',
            data: '0xfbadbaf01'
          }
        ],
        capabilities: {
         /// Check 5792 for supported paramters, you can define the paymasterService        
        }
      }]
    })
1 Like

You can also checkout this guide which uses Wagmi, but overall you’ll get the general idea about how 5792 works Paymasters (Sponsored Transactions) – Smart Wallet

1 Like