The AbstractClient includes a linkToAgw method that can be used to create a link between an Ethereum Mainnet wallet and an Abstract Global Wallet.

Usage

import { linkableWalletActions } from "@abstract-foundation/agw-client";
import { createWalletClient, custom } from "viem";
import { sepolia, abstractTestnet } from "viem/chains";

export default function LinkWallet() {
  async function linkAgwWallet() {
    // Initialize a Viem Wallet client: (https://viem.sh/docs/clients/wallet)
    // And extend it with linkableWalletActions
    const client = createWalletClient({
      chain: sepolia,
      transport: custom(window.ethereum!),
    }).extend(linkableWalletActions());

    // Call linkToAgw with the AGW address 
    const { l1TransactionHash, getL2TransactionHash } =
      await client.linkToAgw({
        agwAddress: "0x...", // The AGW address to link to
        enabled: true, // Enable or disable the link
        l2Chain: abstractTestnet, 
      });

    // Get the L2 transaction hash once the L1 transaction is confirmed
    const l2Hash = await getL2TransactionHash();
  }

  return <button onClick={linkAgwWallet}>Link Wallet</button>;

}

Parameters

agwAddress
Address
required

The address of the Abstract Global Wallet to link to.

enabled
boolean
required

Whether to enable or disable the link between the wallets.

l2Chain
Chain
required

The Abstract chain to create the link on (e.g. abstractTestnet).

account
Account

The account to use for the transaction.

Returns

l1TransactionHash
Hash

The transaction hash of the L1 transaction that initiated the link.

getL2TransactionHash
() => Promise<Hash>

A function that returns a Promise resolving to the L2 transaction hash once the L1 transaction is confirmed.