Account API methods that let you interact with the user's account. Can be accessed via client.account. Look for more samples below.

const balance = await client.account.refreshBalance();
console.log(balance);

Hierarchy (View Summary)

Constructors

Properties

client: ApiClient
currentAccount: CurrentAccount = ...

Current account data.

eip712: EIP712Helper
listeners: {} = {}
provider: AbstractProvider

Methods

  • Dispatch an event to all listeners

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • data: {}[T]

    Returns void

  • Create Ethers.js Wallet instance from username and password. This method is used internally to create a wallet for the user. You can use this method to create a wallet if you need to sign transactions.

    Parameters

    • username: string

      Sogni account username

    • password: string

      Sogni account password

    Returns Wallet

    const wallet = client.account.getWallet('username', 'password');
    console.log(wallet.address);
  • Login with username and password. WebSocket connection is established after successful login.

    Parameters

    • username: string
    • password: string

    Returns Promise<LoginData>

    await client.account.login('username', 'password');
    console.log('Logged in');
  • Logout the user and close the WebSocket connection.

    Returns Promise<void>

    await client.account.logout();
    console.log('Logged out');
  • Remove an event listener

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns void

  • Add an event listener, returns a function that can be called to remove the listener

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns () => void

  • Add an event listener that will be called only once

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns () => void

  • Refresh the balance of the current account.

    Usually, you don't need to call this method manually. Balance is updated automatically through WebSocket events. But you can call this method to force a balance refresh.

    Returns Promise<BalanceData>

    const balance = await client.account.refreshBalance();
    console.log(balance);
    // { net: '100.000000', settled: '100.000000', credit: '0.000000', debit: '0.000000' }
  • Restore session with username and access token.

    You can save access token that you get from the login method and restore the session with this method.

    Parameters

    • username: string
    • token: string

    Returns void

    const { username, token } = await client.account.login('username', 'password');
    localStorage.setItem('sogni-username', username);
    localStorage.setItem('sogni-token', token);
    const username = localStorage.getItem('sogni-username');
    const token = localStorage.getItem('sogni-token');
    if (username && token) {
    client.account.setToken(username, token);
    console.log('Session restored');
    }
  • Switch between fast and relaxed networks. Note: This method will close the current WebSocket connection and establish a new one. Do not call this method if you have any active projects.

    Parameters

    Returns Promise<void>

    client.apiClient.once('connected', ({ network }) => {
    console.log('Switched to the network:', network);
    });
    await client.account.switchNetwork('fast');
  • Get the transaction history of the current account.

    Parameters

    Returns Promise<{ entries: TxHistoryEntry[]; next: TxHistoryParams }>

    Transaction history entries and next query parameters

    const { entries, next } = await client.account.transactionHistory({
    status: 'completed',
    limit: 10,
    address: client.account.currentAccount.walletAddress
    });
  • Get the balance of the wallet address.

    This method is used to get the balance of the wallet address. It returns $SOGNI and ETH balance.

    Parameters

    • walletAddress: string

    Returns Promise<{ ether: string; token: string }>

    const address = client.account.currentAccount.walletAddress;
    const balance = await client.account.walletBalance(address);
    console.log(balance);
    // { token: '100.000000', ether: '0.000000' }