Skip to content
A client to interact with gxchain implemented in js
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE
bin feat: add chain api get_dynamic_global_properties and api descriptions Jan 23, 2019
dist
docs chore: upgrade dependencies to fix vulnerabilities Jun 10, 2019
es chore: upgrade dependencies to fix vulnerabilities Jun 10, 2019
example
lib chore: upgrade dependencies to fix vulnerabilities Jun 10, 2019
test chore: optimize bundle size Mar 12, 2019
.babelrc chore: change babel-env to babel runtime Mar 14, 2019
.eslintrc
.gitignore chore: add docs Jan 30, 2019
.npmignore chore: change babel-env to babel runtime Mar 14, 2019
LICENSE MIT License Jul 4, 2018
README.md Update README.md Apr 11, 2019
package.json chore: upgrade dependencies to fix vulnerabilities Jun 10, 2019
webpack.config.js chore: remove webpack-bundle-analyzer May 24, 2019
yarn.lock chore: update doc Mar 21, 2019

README.md

GXClient

GXClient is a wrapped toolkit of gxbjs, a client to interact with gxchain apis.

You can get more info on docs.

Install

npm install gxclient --save

Usage(CLI)

$ npm install gxclient -g
$ gxclient -h
Usage: gxclient [cmd]

Options:
  -V, --version                                                                              output the version number
  -v --version                                                                               print gxclient version
  -h, --help                                                                                 output usage information

Commands:
  list|ls                                                                                    List all apis
  generate_key                                                                               Generate gxchain key pairs
  private_to_public <private_key>                                                            Export public key from private key
  is_valid_private <private_key>                                                             Check if private key is valid
  is_valid_public <public_key>                                                               Check if public key is valid
  register [options] <account_name> <public_key>                                             Register gxchain account
  get_account [options] <account_name>                                                       Get account information by account_name
  get_account_by_public_key [options] <public_key>                                           Get account information by account_name
  get_object [options] <object_id>                                                           Get object by object_id
  get_account_balances|get_account_balance [options] <account_name>                          Get account balances by account_name
  get_asset [options] <symbol>                                                               Get asset info by asset symbol
  get_block [options] <block_height>                                                         Get block by block height
  transfer [options] <to> <memo> <amount_asset> [boradcast]                                  Send a transfer transaction
  vote [options] <account_ids> [overwrite] [fee_asset_id] [boradcast]                        Vote for TrustNodes
  call_contract [options] <contract_name> <method_name> <params> [amount_asset] [boradcast]  Call smart contract method
  get_contract_tables [options] <contract_name>                                              Get contract table by contract_name
  get_contract_abi [options] <contract_name>                                                 Get contract abi by contract_name
  get_table_objects [options] <contract_name> <table_name> [start] [limit]                   Get table records by contract_name and table_name
  broadcast [options] <tx>                                                                   broadcast transaction
  get_chain_id [options]                                                                     get_chain_id

Usage(Client)

import GXClientFactory from "gxclient";

const private_key = "5Ka9YjFQtfUUX2Ddnqka...";
const account_name = "gxcaccount";
const asset_precicion = 5;

let client = GXClientFactory.instance({keyProvider:private_key, account:account_name,network:"wss://testnet.gxchain.org"});

// set broadcast to false so we could calculate the fee before broadcasting
let broadcast = true;

//Sending 15GXS to gxb456 with memo "GXChain NB"
client.transfer("gxb456", "GXChain NB", "15 GXC", broadcast).then(resp => {
    let transaction = broadcast ? resp[0].trx : resp;
    let txid = broadcast ? resp[0].id : "";
    console.log(JSON.stringify(transaction));
    console.log("txid:", txid, "fee:", transaction.operations[0].fee.amount / Math.pow(10, asset_precicion));
    // > txid: f28d27ac74649a76f58c9b84fb7ea700163e31c4 fee: 0.0118
    // Since gxchain implemented dpos consensus, the transaction will be confirmed until the block becomes irreversible
    // You can find the logic when a transfer operation was confirmed in the example of detectTransaction
}).catch(ex => {
    console.error(ex);
});

APIs

API documents

Other

  • It's very welcome for developers to translate this project into different programing languages
  • We are looking forward to your pull requests
You can’t perform that action at this time.