Class: WalletConnection
walletAccount.WalletConnection
This class is used in conjunction with the BrowserLocalStorageKeyStore.
It redirects users to NEAR Wallet for key management.
This class is not intended for use outside the browser. Without window
(i.e. in server contexts), it will instantiate but will throw a clear error when used.
See
https://docs.near.org/tools/near-api-js/quick-reference#wallet
Example
// create new WalletConnection instance
const wallet = new WalletConnection(near, 'my-app');
// If not signed in redirect to the NEAR wallet to sign in
// keys will be stored in the BrowserLocalStorageKeyStore
if(!wallet.isSignedIn()) return wallet.requestSignIn()
Constructors
constructor
new WalletConnection(near
, appKeyPrefix
)
Parameters
Name | Type |
---|---|
near | Near |
appKeyPrefix | string |
Defined in
Methods
account
account(): ConnectedWalletAccount
Returns the current connected wallet account
Returns
Defined in
getAccountId
getAccountId(): string
Returns authorized Account ID.
Example
const wallet = new WalletConnection(near, 'my-app');
wallet.getAccountId();
Returns
string
Defined in
isSignedIn
isSignedIn(): boolean
Returns true, if this WalletConnection is authorized with the wallet.
Example
const wallet = new WalletConnection(near, 'my-app');
wallet.isSignedIn();
Returns
boolean
Defined in
isSignedInAsync
isSignedInAsync(): Promise
<boolean
>
Returns promise of completing signing in after redirecting from wallet
Example
// on login callback page
const wallet = new WalletConnection(near, 'my-app');
wallet.isSignedIn(); // false
await wallet.isSignedInAsync(); // true
Returns
Promise
<boolean
>
Defined in
requestSignIn
requestSignIn(options
): Promise
<void
>
Redirects current page to the wallet authentication page.
Example
const wallet = new WalletConnection(near, 'my-app');
// redirects to the NEAR Wallet
wallet.requestSignIn({ contractId: 'account-with-deploy-contract.near' });
Parameters
Name | Type | Description |
---|---|---|
options | SignInOptions | An optional options object |
Returns
Promise
<void
>
Defined in
requestSignTransactions
requestSignTransactions(__namedParameters
): Promise
<void
>
Requests the user to quickly sign for a transaction or batch of transactions by redirecting to the NEAR wallet.
Parameters
Name | Type |
---|---|
__namedParameters | RequestSignTransactionsOptions |
Returns
Promise
<void
>
Defined in
signOut
signOut(): void
Sign out from the current account
Example
walletConnection.signOut();
Returns
void