window.ethereum.request()
function.
eth_requestAccounts
method will return a Promise. If it resolves, it is an array where the connected address is in the 0th index, and rejects (throw when awaited) when the user declines the request or closes the pop-up. See Errors for a breakdown of error messages Phantom may emit.
When the user accepts the request to connect, the provider will also emit a connect
event that contains the chainId
of the network the user is connected to.
isConnected
boolean.
accountsChanged
event.
If a user changes accounts while already connected to an application, and the new account had already whitelisted that application, then the user will stay connected and Phantom will pass the public key of the new account: