Connecting
Initial Connection
Your app must first request and receive approval to establish a connection before it can sign transactions and messages. The initial connection request will create a popup window that prompts the user for permission to share their wallet address and avatar URL. The popup window will display your app's site assets (name and logo, read more about displaying site assets here).
Your site will be added to the user's Connected Apps if the user agrees to connect with your site. This permission enables your site to connect eagerly without displaying a popup window in the future. The user has the ability to revoke this permission at any time.
The provider emits a Connect
event (see Events) upon connection, and it throws
Error Code 4001
(see Errors) when the user closes the window without connecting.
While the popup is open window.solana.isConnecting
is set to true
.
Connected Apps
Connected Apps are determined by window.location.hostname
. The host name varies for apps using different
subdomains. Apps are required to request permission for each unique subdomain.
Eager Connection
Your app can connect eagerly using window.solana.connect({onlyIfTrusted: true})
without displaying a popup window
if your site's host name is in the user's Connected Apps. The provider will throw Error Code 4001
if your app
is not in the Connected Apps.
Multiple Accounts
Users are able to create and manage multiple accounts with Avana Wallet. The user has the ability to select a specific account when connecting to your app with the popup window. The user does not select a specific account when connecting eagerly.
Eager connections automatically return the account last used with your app. When your app
calls the window.solana.disconnect()
method it will reset the last account to undefined
. The next
time your app connects it will return the account that the user has selected as active
in the wallet. This account
could be different from the prior account returned before the disconnect
event.
User Data
Upon connection the user's public key and avatar URL will become available at window.solana.publicKey
and window.solana.avatarUrl
, respectively.
Auto-Approve
Auto-Approve When Connecting
Auto-Approve In Connected Apps
Avana Wallet allows some apps to request Auto-Approve permission from the user. When the user enables Auto-Approve, Avana Wallet will automatically connect, sign messages and sign transactions on behalf of the user.
Apps that wish to enable Auto-Approve must meet certain criteria for trust, reputation and rationale for needing the feature.
Auto-Approve is disabled by default and a user must manually enable the feature. The user can enable Auto-Approve when connecting for the first time, or by adjusting the setting in Connected Apps.
Examples
try {
const response = await window.solana.connect();
const publicKeyString = response.toString();
// 2vMMvWQJ6ADzSPoUTHrK4PGBHeMwemCUD3ruo46N14am
window.solana.isConnected;
// true
} catch (error) {
// { code: 4001, message: 'User rejected the request' }
}
try {
const response = await window.solana.connect({ onlyIfTrusted: true });
const publicKeyString = response.toString();
// 2vMMvWQJ6ADzSPoUTHrK4PGBHeMwemCUD3ruo46N14am
window.solana.isConnected;
// true
} catch (error) {
// { code: 4001, message: 'User rejected the request' }
}
window.solana.avatarUrl;
// https://placekitten.com/408/287