Skip to main content

Coinbase Adapter

The @web3auth/coinbase-adapter package enables you to connect with injected Coinbase wallet(Extension Wallet) and Smart Wallet.

Installation

npm install --save @web3auth/coinbase-adapter

Parameters

ParameterDescription
chainConfig?Custom Chain Configuration you want to connect with. Defaults to chainConfig passed to EthereumPrivateKeyProvider.
adapterSettings?Adapter settings to fine-tune the connection preferences, you can refer to CoinbaseWalletSDKOptions documentation. The default connection mode is set to "all," which means that users can connect either their Coinbase Injected Wallet or the Smart Wallet.
clientId?Client Id for Web3Auth. You can get the client id from Web3Auth Dashboard.
sessionTime?Allows you to configure the connection validity. Defaults to sessionTime passed to Web3AuthOptions.
web3AuthNetwork?Allows you to configure the Web3AuthNetwork. Defaults to web3AuthNetwork passed to Web3AuthOptions.

Usage

import { CoinbaseAdapter } from "@web3auth/coinbase-adapter";

const coinbaseAdapter = new CoinbaseAdapter({
// This will only allow users to connect with Smart Wallet
// By default, it's set to "all"
adapterSettings: { options: "smartWalletOnly" },
});

// Use your existing Web3Auth instance
web3auth.configureAdapter(coinbaseAdapter);

Use Smart Wallet Features

The Web3Auth provider which is created using the Coinbase Wallet Adapter will be EIP 1193 compatible which means, you won't be able to use the Smart Wallet(ERC 4337) features directly

To use the Smart Wallet ERC 4337 features, you can use the Web3Auth provider to send JSON-RPC requests to the Smart Wallet. For batching and paymaster feature, it uses EIP 5792 wallet_sendCalls method. Learn more about EIP 5792.

Send Batch Requests

// Retrive the Web3Auth provider once the connection is established
const provider = web3auth.provider;

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

Use Paymaster

// Retrive the Web3Auth provider once the connection is established
const provider = web3auth.provider;

const response = await provider.request({
method: "wallet_sendCalls",
params: [
{
version: "1.0",
chainId: "0x01",
from: address[0],
calls: [
{
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
],
capabilities: {
paymasterService: {
url: "YOUR_PAYMASTER_URL",
},
},
},
],
});