window.phantom.solana.connect()
. However, the provider also exposes a request
JSON RPC interface.
connect()
call will return a Promise that resolves when the user accepts the connection request, and reject (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.
isConnected
boolean.
onlyIfTrusted
option into the connect()
call.
connect
event if the application is trusted. If the application is not trusted, Phantom will throw a 4001 error and remain disconnected until the user is prompted to connect without an onlyIfTrusted
flag. In either case, Phantom will not open a pop-up window, making this convenient to use on all page loads.
The following is an example of how a React application can eagerly connect to Phantom.
disconnect
event.
accountChanged
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 PublicKey of the new account: