A client to interact with gxchain via http
npm install gxclientYou can get more info on docs.
`` bash`
npm install gxclient --save
For react-native, the following extra command should be executed before using gxclient:
` bash`
npm i --save react-native-randombytes
npm i --save-dev rn-nodeify@latest
./node_modules/.bin/rn-nodeify --hack --install
` bash`
$ npm install gxclient -g
$ gxclient -h
`bash
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
is_valid_private
is_valid_public
register [options]
get_account [options]
get_account_by_public_key [options]
get_object [options]
get_account_balances|get_account_balance [options]
get_asset [options]
get_block [options]
transfer [options]
vote [options]
call_contract [options]
get_contract_tables [options]
get_contract_abi [options]
get_table_objects [options]
broadcast [options]
get_chain_id [options] get_chain_id
`
`js
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);
});
``
- It's very welcome for developers to translate this project into different programing languages
- We are looking forward to your pull requests