Account

Each Account class instance represents a specific blockchain account. It offers several helper methods to facilitate interaction with that account.

Creation

In most cases, the AccountKit Factory will be used to create Account instances. However, they can also be created manually if the relevant data is provided. Here is a basic example of how to do so:

import { Account } from "@wharfkit/account"
import { APIClient } from "@wharfkit/antelope"

const accountArgs = {
  data: {
    account_name: "teamgreymass",
    // All account data should be passed here.
  },
  client: new APIClient({ url: "https://jungle4.greymass.com" }),
}

const account = new Account(accountArgs)

An optional Contract instance can be passed to the Account class constructor:

import { ContractKit } from "@wharfkit/contract"
import { Account } from "@wharfkit/account"

const client = new APIClient({ url: "https://jungle4.greymass.com" })

const contractKit = new ContractKit({
  client,
})

const contract = await contractKit.load("contractname")

const accountArgs = {
  data: {
    account_name: "teamgreymass",
    // All account data should be passed here.
  },
  client,
  contract,
}

const account = new Account(accountArgs)

Arguments

The only parameter passed to the Account class constructor is an object containing the following configuration data:

  • data: The account’s data. Generally, this will be obtained using a get_account API call.
  • client: An instance of an APIClient that will be used to retrieve blockchain data.

Options

  • contract: An instance of a Contract class that will be used to interact with the account. Defaults to the system contract.

Usage

Once an Account instance is created, the following methods and read-only properties are available:

Methods

  • balance: Retrieves a specific balance for the account.
  • permission: Retrieves a specific account Permission instance.
  • resource: Retrieves a specific Resource instance that contains some information on the account’s resources.
  • resources: Retrieves a Resources instance from the @wharfkit/resources package.
  • setPermission: Creates an Action instance that can be used to set a permission on the account.
  • removePermission: Creates an Action instance that can be used to remove a permission from the account.
  • linkauth: Creates an Action instance that can be used to require an account authorization for a contract action.
  • unlinkauth: Creates an Action instance that can be used to remove the requirement of an account authorization for a contract action.
  • buyRam: Creates an Action instance that can be used to buy RAM for the account.
  • buyRamBytes: Creates an Action instance that can be used to buy RAM in bytes for the account.
  • sellRam: Creates an Action instance that can be used to sell RAM for the account.
  • delegate: Creates an Action instance that can be used to have the account delegate resources.
  • undelegate: Creates an Action instance that can be used to have the account undelegate resources.

Properties

  • accountName: The account name.
  • client: The APIClient instance used to communicate with the blockchain.
  • data: The account’s data.
  • systemContract: A contract instance of the system contract.
  • chain: The chain ID of the blockchain the account is on.
  • systemToken: The system token symbol of the blockchain the account is on.