AddrAccount

Mainly used to quickly query the account status. eg: account balance / transactions / voting info ...

Installation

npm install @vite/vitejs-addraccount --save
yarn add @vite/vitejs-addraccount

Import

import { addrAccount } from '@vite/vitejs';
// Or
import addrAccount from '@vite/vitejs-addraccount';
const { addrAccount } = require('@vite/vitejs-addraccount');

Constructor

  • Constructor Parameters:

    • __namedParameters: object
      • address : HexAddr vite account address
      • client : Client client instance
  • Example:

import WS_RPC from '@vite/vitejs-ws';
import { client, addrAccount, privToAddr } from '@vite/vitejs';
let provider = new WS_RPC("ws://example.com");
let myClient = new client(provider);
let myAddrAccount = new addrAccount({
    client: myClient,
    address: 'your address'    // Eg: vite_69f3bdb5cdcfa145ae6cc42593a89088ff3dac587eb692d689
});
myAddrAccount.getBalance().then((result) => {
    console.log(result);
}).catch((err) => {
    console.warn(err);
});

Properties

Name Type Description
address string hex address
realAddress string real address

Methods

getBalance

Get balance, including unreceived tokens. client.getBalance

  • Return

    • Promise< { balance, onroad } >
  • Example

// ...
myAddrAccount.getBalance().then((result) => {
    console.log(result);
}).catch((err) => {
    console.warn(err);
});

sendAccountBlock

client.sendRawTx

  • Parameters

    • __namedParameters: object
      • accountBlock : AccountBlock Signed accountblock
  • Return:

    • Promise< AccountBlock >

getTxList

client.getTxList

  • Parameters

    • __namedParameters: object
      • index: number
      • pageCount?: number Default 50
      • totalNum?: number Total transaction amount. If totalNum === 0 , return Object { totalNum: 0, list: [] } ; If !totalNum , auto get totalNum with Gvite-RPC api ledger_getAccountByAccAddr .
  • Return:

    • Promise< { list, totalNum } >
  • Example

// ...
myAddrAccount.getTxList({
    index: 0,
    pageCount: 50
}).then((data) => {
    let txList = data.list || [];
    console.log(txList);
});

callOffChainContract

Query contract status. client.callOffChainContract

  • Parameters

    • __namedParameters: object
      • abi
      • offChainCode : Hex 合约代码
  • Return:

    • Promise< result >

getOnroad

Get unreceived tokens. Gvite-RPC onroad_getOnroadInfoByAddress

  • Return:
    • Promise

getOnroadBlocks

Get unreceived account block list. Gvite-RPC onroad_getOnroadBlocksByAddress

  • Parameters

    • __namedParameters: object
      • index : number page index
      • pageCount : number count
  • Return:

    • Promise
  • Example

// ...
myAddrAccount.getOnroadBlocks({
    index: 0,
    pageCount: 10
}).then((onroad) => {
    console.log(onroad);
});

getBlocks

Get account block list. Gvite-RPC ledger_getBlocksByAccAddr

  • Parameters

    • __namedParameters: object
      • index : number page index
      • pageCount : number count
  • Return:

    • Promise

getAccountBalance

Get account balance. Gvite-RPC ledger_getAccountByAccAddr

  • Return:
    • Promise

getLatestBlock

Get last block. Gvite-RPC ledger_getLatestBlock

  • Return:
    • Promise

getBlockByHeight

Gvite-RPC ledger_getBlockByHeight

  • Parameters

    • height
  • Return:

    • Promise

getBlocksByHash

Gvite-RPC ledger_getBlocksByHash

  • Parameters

    • __namedParameters: object
      • hash
      • num
  • Return:

    • Promise

getBlocksByHashInToken

Gvite-RPC ledger_getBlocksByHashInToken

  • Parameters

    • __namedParameters: object
      • hash
      • tokenId
      • num
  • Return:

    • Promise

getPledgeQuota

Gvite-RPC pledge_getPledgeQuota

  • Return:

    • Promise
  • Example

// ...
myAddrAccount.getPledgeQuota().then((pledgeQuota) => {
    console.log(pledgeQuota);
});

getPledgeList

Gvite-RPC pledge_getPledgeList

  • Parameters

    • __namedParameters: object
      • index : number page index
      • pageCount : number count
  • Return:

    • Promise

getRegistrationList

Gvite-RPC register_getPledgeList

  • Return:

    • Promise
  • Example

// ...
myAddrAccount.getRegistrationList().then((list) => {
    console.log(list);
});

getVoteInfo

Gvite-RPC vote_getVoteInfo

  • Return:

    • Promise
  • Example

// ...
myAddrAccount.getVoteInfo().then((voteInfo) => {
    console.log(voteInfo);
});

getTokenInfoListByOwner

Gvite-RPC mintage_getTokenInfoListByOwner

  • Return:
    • Promise

getBlock

This part will automatically wrap the method in client.builtinTxBlock (For quickly calling the methods of client.builtinTxBlock )

How to achieve

  1. accountBlock.accountAddress = this.address
  2. Get the legal accountBlock by client.builtinTxBlock[methodName]

Code

for (const key in this._client.builtinTxBlock) {
    if (key === '_client') {
        continue;
    }
    this.getBlock[key] = (block, requestType?) => {
        block = block || {};
        block.accountAddress = this.address;
        return this._client.builtinTxBlock[key](block, requestType);
    };
}

How to invoke

  • Parameters

    • accountBlock accountBlock(Can have no accountAddress field)
    • requestType?: string<'async' | 'sync'> Default: async. Options (sync or async) when reformatting accountBlock
  • Return

    • Promise< AccountBlock >
  • Example

// ....
myAddrAccount.getBlock.SBPreg({
    nodeName: 'TEST_NODE',
    toAddress: 'your address',
    amount: '100000000000000000000000',
    tokenId: Vite_TokenId,
    height, 
    prevHash
}).then((block) => {
    console.log(block);
}).catch(err => {
    console.warn(err);
});