Expand description

near-accounts allows for keeping track of data associated with an account as well as storage management.

Usage is quite simple. Start with the required imports

use near_account::{
    impl_near_accounts_plugin, Account, AccountDeposits, Accounts, NearAccountPlugin,
    NearAccountsPluginNonExternal, NewInfo,
};

After, define a struct for what info the contract should store for each account So, for example, if the contract intends to keep track of a message associated with each user

#[derive(BorshDeserialize, BorshSerialize)]
pub struct AccountInfo {
    pub message: String,
}

Then, the contract must implement the NewInfo trait for AccountInfo, so, for example

  impl NewInfo for AccountInfo {
  fn default_from_account_id(account_id: AccountId) -> Self {
      Self {
          message: "".to_string(),
          internal_balance: UnorderedMap::new(format!("{}-bal", account_id).as_bytes()),
      }
  }
 }

Finally, all that is left to do is define the contract and call the implementing macro

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
pub struct Contract {
    pub accounts: Accounts<AccountInfo>,
}

impl_near_accounts_plugin!(Contract, accounts, AccountInfo);

For documentation on externally defined methods (publicly callable), please see the NearAccountPlugin trait

For documentation on functions for internal contract use, please see the NearAccountsPluginNonExternal trait and the AccountDeposits trait

Modules

Macros

Structs

Account information and storage cost.

Account information and storage cost.

Traits

Functions for dealing with Near Deposits for an individual account

The Info struct must implement this trait which consists of the composition of BorshSerialize, BorshDeserialize, and NewInfo

Defines the functions which will be exposed as methods for the smart contract

A trait of the AccountInfo struct describing how to construct a default new account