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()

Hierarchy

  • WalletConnection

Constructors

Methods

  • Returns authorized Account ID.

    Returns string

    Example

    const wallet = new WalletConnection(near, 'my-app');
    wallet.getAccountId();
  • Returns true, if this WalletConnection is authorized with the wallet.

    Returns boolean

    Example

    const wallet = new WalletConnection(near, 'my-app');
    wallet.isSignedIn();
  • Returns promise of completing signing in after redirecting from wallet

    Returns Promise<boolean>

    Example

    // on login callback page
    const wallet = new WalletConnection(near, 'my-app');
    wallet.isSignedIn(); // false
    await wallet.isSignedInAsync(); // true
  • Redirects current page to the wallet authentication page.

    Parameters

    • options: SignInOptions

      An optional options object

    Returns Promise<void>

    Example

    const wallet = new WalletConnection(near, 'my-app');
    // redirects to the NEAR Wallet
    wallet.requestSignIn({ contractId: 'account-with-deploy-contract.near' });
  • Constructs string URL to the wallet authentication page.

    Parameters

    • options: SignInOptions

      An optional options object

    Returns Promise<string>

    Example

    const wallet = new WalletConnection(near, 'my-app');
    // return string URL to the NEAR Wallet
    const url = await wallet.requestSignInUrl({ contractId: 'account-with-deploy-contract.near' });
  • Requests the user to quickly sign for a transaction or batch of transactions by redirecting to the wallet.

    Parameters

    • options: RequestSignTransactionsOptions

      A required options object

    Returns void

  • Constructs string URL to the wallet to sign a transaction or batch of transactions.

    Parameters

    • options: RequestSignTransactionsOptions

      A required options object

    Returns string

Generated using TypeDoc