Skip to main content

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

NameType
nearNear
appKeyPrefixstring

Defined in

wallet-account.ts:87

Methods

account

account(): ConnectedWalletAccount

Returns the current connected wallet account

Returns

ConnectedWalletAccount

Defined in

wallet-account.ts:273


getAccountId

getAccountId(): string

Returns authorized Account ID.

Example

const wallet = new WalletConnection(near, 'my-app');
wallet.getAccountId();

Returns

string

Defined in

wallet-account.ts:159


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

wallet-account.ts:128


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

wallet-account.ts:142


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

NameTypeDescription
optionsSignInOptionsAn optional options object

Returns

Promise<void>

Defined in

wallet-account.ts:177


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

NameType
__namedParametersRequestSignTransactionsOptions

Returns

Promise<void>

Defined in

wallet-account.ts:205


signOut

signOut(): void

Sign out from the current account

Example

walletConnection.signOut();

Returns

void

Defined in

wallet-account.ts:265