Skip to content

eth_requestAccounts

Defined in EIP-1102

Calling this method MAY trigger a user interface that allows the user to approve or reject account access for a given app.

Returns

Array<string>

An array of Ethereum addresses, which the connected user controls.

Errors

CodeMessage
4001User denied connection request

Examples

import { useState } from "react";
import { sdk } from "./config";

export default function App() {
  const [address, setAddress] = useState(undefined);
  const provider = sdk.makeWeb3Provider({ options: "smartWalletOnly" });

  const handleClick = async () => {
    const accounts = await provider.request({ method: "eth_requestAccounts" });
    setAddress(accounts[0]);
  };

  return (
    <>
      {!address && (
        <button
          onClick={handleClick}
        >
          Connect
        </button>
      )}
      {address && <p>Connected address: {address}</p>}
    </>
  );
}