# Java SDK

# Quick Start

Instantiate "topj".

package org.topnetwork;


import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class main {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
         }
}

# Network

  • RPC API
HttpService httpService = new HttpService(serverUrl);
  • Restful API
HttpService httpService = new HttpService(serverUrl);

# Interface Overview

Interface Description
topj.setTransactionReceiptProcessor() Transaction initialization settings.
topj.genAccount() Generate an account object by the private key.
topj.passport() Get an on-chain access identity token.
topj.getChainInfo() Get mainchain informaiton.
topj.getAllStandBys Get all nodes in the candidate pool.
topj.getStandBys() Get individual candidate node.
topj.getCGP() Get on-chain governance parameters.
topj.getLastUnitBlock() or topj.getUnitBlockByHeight() Get unit block by block height.
topj.getLastTableBlock() or topj.getTableBlockByHeight() Get table block by block height.
topj.getAccount() Get account information on the chain.
topj.transfer() Send TOP to another account address.
topj.getTransaction() Query account transaction details.
topj.stakeGas() Lock TOP to get gas.
topj.unStakeGas() Unlock the TOP used to get gas.
topj.registerNode() Register miner.
topj.queryNodeInfo() Get miner information.
topj.updateNodeType() Update miner type.
topj.setNodeName() Set miner name.
topj.stakeDeposit() Increase miner deposit.
topj.unStakeDeposit() Decrease miner deposit.
topj.setDividendRate() Advance node sets dividend ratio.
topj.listVoteUsed() Get account's votes distribution.
topj.unRegisterNode() Unregister miner.
topj.redeemNodeDeposit() Redeem the miner deposit after the miner is cancelled.
topj.stakeVote() Lock TOP to get votes.
topj.unStakeVote() Unlock the TOP used to get votes.
topj.voteNode() Vote for miners.
topj.unVoteNode() Cancel votes for miners.
topj.queryVoterDividend() Get voter dividend details.
topj.claimVoterDividend() Claim voter dividend.
topj.queryNodeReward() Query a single miner’s reward.
topj.queryAllNodeReward() Query all miners‘ reward.
topj.claimNodeReward() Claim miner reward.
topj.submitProposal() Submit proposals.
topj.withdrawProposal() Withdraw proposals.
topj.queryProposal() Query proposal details.
topj.tccVote() TCC vote on proposals.
Tools Description
transferActionParam.decode Parse out the amount and note in the transfer transaction body.
xTransaction.isSuccess Determine whether the transaction is successful.
Transaction Object All transaction requests return this object.

# Transaction Initialization Settings

After the SDK sends a transaction request, the program cannot directly return the transaction execution result, so you need to loop to the chain to query whether the transaction is successful. The default query is once every 3 seconds, and the loop is 100 times for a total of 5 minutes. If the transaction still cannot be queried at this time, the program returns the transaction hash.

The "setTransactionReceiptProcessor" method can modify the cycle query interval and the number of cycles. For example, the sample code is modified to query once every 5 seconds and cycle 3 times for a total of 15 seconds.

Request Method

topj.setTransactionReceiptProcessor

Request Parameters

"TransactionReceiptProcessor" is an abstract class. There are two implementation classes, "PollingTransactionReceiptProcessor" and "NoOpProcessor", which can be instantiated and passed in.

"PollingTransactionReceiptProcessor" means that it will poll "attempts" times with an interval of "sleepDuration" milliseconds. The parameters required for instantiation are shown in the following table.

Parameter Name Required Default Value Parameter Type Description
sleepDuration Yes - Long Waiting interval, in "ms".
attempts Yes - Int Cycles.

You can also set it to not loop, return the transaction hash directly, and pass in the "NoOpProcessor" object interface. The code is:

topj.setTransactionReceiptProcessor(new NoOpProcessor())

"NoOpProcessor" means to return the hash directly without parameters.

Request Sample

package org.topnetwork;

import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class SetTransactionReceiptProcessor {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://192.168.50.159:19081");
        topj = Topj.build(httpService);
        PollingTransactionReceiptProcessor transactionReceiptProcessor = new PollingTransactionReceiptProcessor(5000, 5);
        topj.setTransactionReceiptProcessor(transactionReceiptProcessor);
    }
}

# Chain Basic Operations

# Generate Account Object By Private key

The account object is generated locally based on the private key, and the object contains parameters such as private key, public key, and account address.

Request Method

topj.genAccount

Request Parameters

Parameter Name Required Default Value Parameter Type Description
privateKey Yes - String Private Key.

Response Parameters

Parameter Name Parameter Type Description
address String Account address/
balance Uint64 Account balance.
lastUnitHeight Uint64 The unit block height of the latest consensus successful transaction.
netType Integer Net type: "0"--mainnet, "1"--testnet.
nonce Uint64 The latest consensus and successful transaction nonce of this account and it is unique.
privateKey String The private key is used for decryption and signing transaction. Please do not share your private key with other people, so as not to cause asset loss!
privateKeyBytes String The Byte format of the private key.
publicKey String The public key and the private key always appear in pairs.
Used to encrypt and verify signature.
sequenceId String The number of client sessions, increasing.

Locally generated account is mainly used to generate public and private keys and addresses. Other parameters, except "token", are all initial values. You need to run the topjs.getAccount method to get the real value on the chain.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.procotol.http.HttpService;

public class GenAccount {
    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args){
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        account = topj.genAccount();
        System.out.println(account.getPublicKey() + "......" + account.getPrivateKey() + "..........."+ account.getAddress());
        String os = JSON.toJSONString(account);
        System.out.println(os);
    }
}

Response Sample

{
	"address": "T8000010eaeb3a8f2e34b36d34d41e1efeeb1bb7f5c1f9",
	"balance": 0,
	"lastUnitHeight": 0,
	"netType": 0,
	"nonce": 0,
	"privateKey": "071c178f9b5cd200fae90e582d4e68f5469343d87e52d29e5b8dc4dd6f8c554b",
	"privateKeyBytes": "BxwXj5tc0gD66Q5YLU5o9UaTQ9h+UtKeW43E3W+MVUs=",
	"publicKey": "145cb2e8f896f631c0cf5ea831d79a7e6444bc288f9bdf9a1ec0280e512cd87945c4214c4f1bf4cbf0d3f42ef1e2de72e4bfc628eae28b5360a0152ca947e6a9",
	"sequenceId": "4572172267121319642"
}

# Get On-chain Access Identity Token

According to the account to obtain the identity token, each account token is different. In all subsequent requests, the token parameter is required.

Request Method

topj.passport

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

The return value contains the token field, which has been directly put into the account object for use in subsequent calls.

Parameter Name Parameter Type Description
secret_key String Secret key.
signature_method String Signature method.
signature_ver_code String Signature method version.
identity_token String identity token, used to interact with the chain. This parameter is required for all subsequent requests.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.PassportResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class PassPort {

    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        ResponseBase<PassportResponse> token =topj.passport(account);
        System.out.println(JSON.toJSONString(token));
    }
}

Response Sample

{
	"data": {
		"identity_token": "62295a21-b338-45bd-a6de-96ff47371482",
		"secret_key": "ec6b265c-36be-4995-b5fa-b5e6476d6228",
		"signature_method": "hmac_sha2",
		"signature_ver_code": "1.0"
	},
	"errmsg": "OK",
	"errno": 0,
	"sequence_id": "-6181715942575529103"
}

# Get Mainchain Information

Request Method

topj.getChainInfo

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account Object.

Response Parameters

Parameter Name Parameter Type Description
first_timerblock_hash String Hash of the first clock block.
first_timerblock_stamp Uint64 Generation time of the first clock block.
init_total_locked_token Uint64 Total TOP Token initially locked by the system. The system initializes the exchange rate of gas = total gas/ total locked amount of the system to avoid the system initialized exchange rate of gas to be 0.
token_price Uint64 Exchange rate of locking TOP Token for gas, measured in tgas/top, which changes dynamically with the change of locked TOP token in the system.
total_gas_shard Uint32 Total gas per shard for 24 hours.
validator_group_count Uint32 Number of validator group.
network_activate_time uint64 Mainnet activation time.

Request Parameters

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ChainInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetChainInfo {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        System.out.println(JSONObject.toJSON(account.getBalance()));
        ResponseBase<ChainInfoResponse> chainInfo = topj.getChainInfo(account);
        System.out.println(JSONObject.toJSON(chainInfo));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"token_price": "8640",
		"network_activate_time": 1,
		"init_total_locked_token": 1000000000000000,
		"validator_group_count": "4",
		"total_gas_shard": "2160000000000",
		"first_timerblock_stamp": "1573189200",
		"first_timerblock_hash": "72fe32a913ce06c6e1942f51ee6ad33682588baca7c75de56622474ed41df9f1"
	},
	"sequence_id": "-5300293571980210978",
	"errmsg": "OK"
}

# Get All Candidate Nodes

Get information of all nodes in the candidate pool contract on the Beacon, including information of nodes those have been elected as the edge, archive, validator, auditor, Beacon and Beacon.

Request Method

topj.getAllStandBys

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Parameter Name Parameter Type Description
consensus_public_key String The key used when the node is working. Account public-private key pair or non-asset public-private key pair.
node_id String Node account address.
stake Uint64 Node stake.
program_version String Program version.
is_genesis_node String Whether it is a genesis node.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.StandBysResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetAllStandBys {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        System.out.println(account.getAddress());
        topj.passport(account);
        ResponseBase<StandBysResponse> s = topj.getAllStandBys(account);
        System.out.println(JSONObject.toJSON(s));
    }


}

Response Sample

{
	"errno": 0,
	"data": {
		"activated_state": "activated",
		"edge": [{
			"stake": 0,
			"consensus_public_key": "BDrdTUhkR5+biKfgqhG2AjdzTqcJeLerhUzvAMAVQucqaVThKs0TsEBGrMZddvnc/5ObxHt80NqbFWS3o+S0uBo=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000LKvLi6cVAHQEV12ZebsQC9n3RGzJVr1dbx"
		}],
		"auditor": [{
			"stake": 1128237,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}],
		"validator": [{
			"stake": 1062,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 406,
			"consensus_public_key": "BLdLvnf1PANd4CwDCd7evDM00QHle+XzsVnxgHqaNyV1XVvAPGIIptXjF+fVBpDy9ouA/4vUh7wUykbeTPb4f+g=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000Li1eU7Ngm2qKhbeToGdP84yxVnP7aWEdDM"
		}],
		"archive": [{
			"stake": 0,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}],
		"root_beacon": [{
			"stake": 3418900,
			"consensus_public_key": "BFo8gXU9sHhmAIcZq0JrPamppSfz7LGXi8fwh6oUcj6k7oOhqiaaj9sDIsppoNXP3IoBpD4JgLh+NjvPg3ziDQI=",
			"program_version": "1.2.7",
			"is_genesis_node": "false",
			"node_id": "T00000LKEuoeqX5nUmckb35tQQKhQC3UfgCWgG7Z"
		}, {
			"stake": 0,
			"consensus_public_key": "BGhYfKmFKHg+UWHEXI014I1OXWTFu2LOR+zqfp76sw9en0y+T80J6Sx4cSKy5fB4L9UVPRghC4XW6tBaWhRz3Ag=",
			"program_version": "1.1.0",
			"is_genesis_node": "true",
			"node_id": "T00000Lhqt91nNEt5uBfgG9ACFsuQw6taFkP1Xd3"
		}]
	},
	"sequence_id": "6362420583714881307",
	"errmsg": "OK"
}

# Get Single Candidate Node

Get information about a single node in the candidate pool.

Request Method

topj.getStandBys

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
nodeAddr Yes -

Response Parameters

Parameter Name Parameter Type Description
consensus_public_key String The key used when the node is working. Account public-private key pair or non-asset public-private key pair.
node_id String Node account address.
stake Uint64 Node stake.
program_version string Program version.
is_genesis_node bool Whether it is a genesis node.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.StandBysDetail;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetStandBys {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        ResponseBase<StandBysDetail> sb = topj.getStandBys(account, "T00000LYHXC2soSmkvcySdKqc56FBh5XMUeAbqsd");
        System.out.println(JSONObject.toJSON(sb));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"stake": 0,
		"consensus_public_key": "BFj83APhuMt425X26Dix9iuErAi0XjRklXbZpxghqRT/JZwDUg5saEgBeQmJOW0EW8ITFAp/Ld8ElEq594o/KSA=",
		"program_version": "1.1.0",
		"is_genesis_node": "true",
		"node_id": "T00000LYHXC2soSmkvcySdKqc56FBh5XMUeAbqsd"
	},
	"sequence_id": "981421573870353020",
	"errmsg": "OK"
}

# Get On-chain Governance Parameters

Request Method

topj.getCGP

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Please refer to On-chain Governance Parameters.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.CGPResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetCGP {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount();
        topj.passport(account);
        ResponseBase<CGPResponse> cgp = topj.getCGP(account);
        System.out.println(JSONObject.toJSON(cgp));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"min_tx_deposit": "100000",
		"backward_node_lock_duration_increment": "103680",
		"rec_election_interval": "259201",
		"votes_report_interval": "30",
		"zone_election_trigger_interval": "181",
		"edge_election_interval": "360",
		"toggle_whitelist": "0",
		"election_rotation_count_ratio": "8",
		"unlock_gas_staked_delay_time": "8640",
		"whitelist": "T00000LabjxtsmwfhVW7RK1ezUZNUMdKUv6gxTG5,T00000LZgWW5jsGR4Bg62ZZWbncioWQKDRXtVyJN,T00000LNTsgQq8sGgXmJSNMqEpze9bnqjrTpbk4K,T00000LZtiM94bYBmiC5261Y6MnggQNTjyrFb6Ja,T00000LaPL3pVbkxEfE8wSCanWFtnBVoQaxWkejS,T00000LUkbBh9rPA1RFcbKrJbwj5uQgHK93ADJAW,T00000LcvZaypD3bHFHHh4PsXsy5ASDGAD4mmpFr,T00000LbgaCLnuxnqaqPh8e9EpeNqsRju6MuCr4z,T00000LSmt4xfNdC2v8xQHRSbfSQ7b5aC1UTXWfo,T00000LcM8Pn37SRF5RaTHZLsRW4wudDVE9BAXy8,T00000Lg24i2TweBikod4UJwmMS8TqgwvHooFYMp,T00000LZiwnEtvrRaxEVNoZxU6mp1CFFwvA3JRhQ,T00000LS2WKtMuE7moMekoiYhk78rdFYvJzayMDK,T00000LZkFxsyiz8nJuruAzdtvi8YhZpmL2U9dXK,T00000LMxyqFyLC5ZWhH9AWdgFcK4bbL1kxyw11W,T00000LhXXoXe5KD6furgsEKJRpT3SuZLuN1MaCf,T00000LgspJnjWPFMwqrMF7KHi3rQKQLYp8E1Yxz,T00000LYpGz3V6QJ52SGumo1yWwX7LyxrQqjDLdq,T00000LQnwSvLmPFvjDgVuJNCLGh6WGKwCkf56uj,T00000LTD37o7rLoPFcgpHWjDQxESSxrGvaNrpGt,T00000LL9s2YtuNUcAoUUrnxcSXBd4W6wSdzjemf,T00000LMzNdxFwAxmd2ZVBreLK2vSS49WzCJVoVG,T00000LMvBMjfoqDQC73oSWo5sD67P5xjk9fQaCe,T00000Lbip8pqD91fVpJHLzyVZAQiQCsmbxyEs6y,T00000LYkwwpkJop7HEMVuqbsDZr4RaHjrF1wssP,T00000LPBpGtTM45MNdfAiTjugfRCiS7WtaqVcm1,T00000LgdJEmsZD8obxJCXUHpy3ZcGhtDbwCRH2h,T00000LhHZFAXAch4J43H62GKbXDNfrW34mDb8m9,T00000LQu5vJcL6EGZy2ZzZusUFrtySYYndSZkw3,T00000LT1KJ2acbULwtY8oYSTHFxayDAF7dzLv4V,T00000Lc8DpPBmVciGm74DLUM9gFhEZwBFZu5ddf,T00000LMhzYYjuDKxbgb1etKQd57CP8xcbyb7RG9,T00000LSkemDwk8kFWmXLoasgX6C3ffGRxVPjDLf,T00000LhLwuX3Z5BgKpxQZx6c8dAgJXMKF6CTBst,T00000LWY6p1GfHJQ65NyiXGnEtc51i71ujuGDJQ,T00000LMnPbhyrVSjuZPTibWGWK112sCor6aVcvm,T00000LYE6tEd3hiDuS1r2qdv8TTM1n6pPh8gNqp,T00000Lca54DkBgCy4KGnaNCpwsPEeWKAtCd4ZXH,T00000LZyVYYEM5DZd6sBDpdrLhoEzGgUGEGWFK3,T00000LgeZE4QqTGB3932gVH1mmpAwF27zyv7zDz,T00000LhmH4c2difu4BqTUag9bb4adAPPPMUZU55,T00000LSSiNCEtthd2ZPYSfoXRc8cC1dQh8hTFpm,T00000LWCo6FDr2w7fai9LdvQRAyDhratqubngX6,T00000LT1fiim7qkMnQE3aSFMcJPAjJWNzdCh3bx,T00000LT6H8Cuxr1g5vR3sjHDSEim2hds6PL6kSU,T00000LRW3SKquMLh1vPardd7t13xQzQdUKebqrY,T00000LbcZK2pLDDkdfYUciSkSSkSo8hKsJHzVhv,T00000LMUmS4evMZvVxGCM9kwiaZdbHzY6cv8ccx,T00000Lek4eDGNa5Xgnfj1tPaAnBZBX6AiCwFJFf,T00000LMMzgZNF1P9bBQsxbmPsvj6SnD3M2SkFNo,T00000LQH62BkqCYpu5TBd2DqTLh8j438gdfT4E1,T00000LWuAfQogkTN8tyuKJRoHBDtsmaZaqVhXrS,T00000LUXX3qFKX4bn6fvzGmGnY9usnz8JDUd4Pd,T00000LTVQ6xVhK9o1M5sqJ4AYmjMNjSGWF4f4py",
		"max_archive_group_size": "512",
		"validator_reward_ratio": "60",
		"governance_reward_ratio": "4",
		"auditor_reward_ratio": "10",
		"max_gas_contract": "50000000",
		"max_vote_nodes_num": "10000",
		"beacon_tx_fee": "100000000",
		"min_auditor_deposit": "1000000000000",
		"punish_interval_time_block": "8640",
		"zec_election_interval": "259183",
		"workload_per_tableblock": "2",
		"punish_interval_table_block": "368640",
		"sign_block_ranking_reward_threshold_value": "0",
		"max_edge_group_size": "512",
		"min_mainnet_active_votes": "0",
		"min_mainnet_active_validators": "20",
		"total_gas_shard": "2160000000000",
		"cluster_election_interval": "360",
		"min_mainnet_active_auditors": "20",
		"custom_property_name_max_len": "16",
		"min_voter_dividend": "0",
		"min_election_committee_size": "20",
		"initial_total_locked_token": "1000000000000000",
		"rec_standby_pool_update_interval": "11",
		"min_credit": "100000",
		"usedgas_decay_cycle": "8640",
		"cluster_election_minimum_rotation_ratio": "66",
		"sign_block_ranking_publishment_threshold_value": "10",
		"vote_reward_ratio": "20",
		"award_auditor_credit": "10000",
		"reward_issue_interval": "4297",
		"tx_deposit_gas_exchange_ratio": "20",
		"tx_send_timestamp_tolerance": "300",
		"application_contract_code_max_len": "32768",
		"cross_reading_rec_standby_pool_contract_height_step_limitation": "12",
		"archive_election_interval": "360",
		"max_auditor_rotation_count": "2",
		"fullunit_contain_of_unit_num": "21",
		"min_node_reward": "0",
		"backward_validator_slash_credit": "100000",
		"cpu_gas_exchange_ratio": "40",
		"min_validator_deposit": "500000000000",
		"max_nodedeposit_lock_duration": "3110400",
		"max_election_committee_size": "20",
		"min_auditor_group_size": "4",
		"edge_reward_ratio": "2",
		"max_gas_account": "1000000",
		"min_mainnet_active_archives": "1",
		"additional_issue_year_ratio": "8",
		"sign_block_publishment_threshold_value": "0",
		"sign_block_reward_threshold_value": "80",
		"min_mainnet_active_edges": "1",
		"backward_auditor_slash_credit": "100000",
		"max_auditor_group_size": "7",
		"min_stake_votes_num": "1",
		"free_gas": "25000",
		"max_validator_group_size": "7",
		"min_ratio_annual_total_reward": "2",
		"min_edge_deposit": "200000000000",
		"custom_property_max_number": "128",
		"workload_per_tx": "1",
		"min_votes_num": "1",
		"zec_standby_pool_update_interval": "31",
		"min_validator_group_size": "4",
		"award_validator_credit": "10000",
		"cross_reading_rec_standby_pool_contract_logic_timeout_limitation": "67",
		"dividend_ratio_change_interval": "120960"
	},
	"sequence_id": "5193415160597868506",
	"errmsg": "OK"
}

# Get Unit Block

  • Get the latest height unit block.

Request Method

topj.getLastUnitBlock

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
address Yes - String Account address.
  • Get the specified height unit block

Request Method

topj.getUnitBlockByHeight

Request Method

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
address Yes - String Account address.
height Yes - Integer Block height.

Response Parameters

Parameter Name Parameter Type Description
value Object -
body Object -
lightunit Object Include lightunit_input and lightunit_state.
txs Object The transaction information packaged in this block, the structured is a map array, and the key of the map is a transaction hash, such as: 6e734fed40b907bb64d257968e6a46a79c4ca144088d330b674cc8b545350324
tx_consensus_phase Uint8 Transaction consensus phase:1--self;2--send;3--recv.
enum_transaction_subtype_self = 1, // self operate
enum_transaction_subtype_send = 2, // send to other account
enum_transaction_subtype_recv = 3, // receive from other account
enum_transaction_subtype_recv_ack = 4(confirm), // receive ack from other account
tx_hash string Transaction hash.
hash String The hexadecimal string of this block hash.
header Object -
auditor String The leader that generates block.
auditor_xip String Auditor leader node of this block (xip format).
timerblock_height Uint64 Clock block height.
validator_xip String Validator leader node of this block (xip format).
version String Block version.
height Uint64 Block height.
owner String The account address that owns the unit block.
prev_hash String The hexadecimal of the hash of the previous block.
table_height Uint64 Table block height.
timestamp Uint64 Block timestamp.

Account Native Property

Property Code Field Property Name Property Type Description
XPROPERTY_CONTRACT_CODE "@1" String The specific code for contract execution.
XPROPERTY_LOCK_TOKEN_KEY "@4" Map Set of locked TOP tokens by transactions under an account.
XPROPERTY_LOCK_TOKEN_SUM_KEY "@5" String Total amount of locked TOP tokens.
XPORPERTY_SUB_ACCOUNT_KEY "@13" Llist List of sub account.
XPORPERTY_CONTRACT_SUB_ACCOUNT_KEY "@14" List List of contract sub account.
XPORPERTY_CONTRACT_PARENT_ACCOUNT_KEY "@15" String Parent account of contract account.
XPROPERTY_USED_TGAS_KEY "@30" String Value of gas attenuation.
XPROPERTY_LAST_TX_HOUR_KEY "@32" String The logical clock at @30 was last updated.
XPROPERTY_USED_DISK_KEY "@34" String Disk used, which is useless temporarily this period.
XPROPERTY_CONTRACT_TGAS_LIMIT_KEY "@37" String gas_limit: The upper limit of the gas fee that the user is willing to pay for the transaction.
XPROPERTY_PLEDGE_VOTE_KEY "@45" List Used for exchanging votes, unlocking the TOP tokens used for exchanging votes, storing all votes exchanging transactions of account.
XPROPERTY_EXPIRE_VOTE_TOKEN_KEY "@46" String All the TOP tokens that have expired when exchanging votes.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.block.UnitBlockResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetLastUnitBlock {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");

        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<UnitBlockResponse> sb = topj.getLastUnitBlock(account, account.getAddress());
        String s = JSON.toJSONString(sb.getData());
        System.out.println(s);
    }
}

Response Sample

{
  "value":{
    "body":{
      "lightunit":{
        "txs":[
          {
            "tx_consensus_phase":"send",
            "tx_hash":"0xebcaad282eb7c03886372b26493b3d075ee0ae239839753efff9b0b8317c0656"
          }]
      }
    },
    "hash":"3ba75a0a15b97acfe99e787332e771380fd7cc6f9be5325f8a0173edf3ae68cc",
    "header":{
      "auditor":"T00000LPXfPyqcCrzgVyKZEhqcKtLp5yGDiRxHSL",
      "auditor_xip":"1c000000000007b:f60000ff00040404",
      "timerblock_height":7707862,
      "validator_xip":"1c000000000007b:f60000ff000503ff",
      "version":"196608"
    },
    "height":128,
    "owner":"T00000LSygN1JSvh6U1TuAH9FZa26rdfmTajcxtX",
    "prev_hash":"452efe0114610b5cb85a4cb99f365a4ead3ee802d7162312a42f7bb00c177261",
    "table_height":465,
    "timestamp":1650267820
  }
}

# Get Table Block

  • Get the latest height table block.

Request Method

topj.getLastTableBlock

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
address Yes - String Account address.
  • Get the specified height unit block

Request Method

topj.getTableBlockByHeight

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
address Yes - String Account address.
height Yes - Integer Block height.

Response Parameters

Parameter Name Parameter Type Description
data Object -
value Object -
body Object -
tableblock Object The tableblock contains multiple units. When there is no new transaction on the chain for a long time, the latest height data of the tableblock is "null".
units Object Tableblock stores information of several unit blocks.
account String Account address.
unit_height Uint64 Unit block height.
hash String The hexadecimal String of this block hash.
header Object -
auditor String The leader that generates block.
auditor_xip String Auditor leader node of this block (xip format).
multisign_auditor string The node that generates block. multisign_auditor and multisign_validator cannot be empty at the same time.
multisign_validator string The node that packages and generates block.
timerblock_height Uint64 Clock block height.
validator_xip String Validator leader node of this block (xip format).
version String Block version.
height Uint64 Block height.
owner String The account address that owns the table block.
prev_hash String The hexadecimal of the hash of the previous block.
table_height Uint64 Table block height, same as height.
timestamp Uint64 Block timestamp.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.block.TableBlockResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;

public class GetLastTableBlock {

    private static Topj topj = null;
    private static Account account = null;

    public static void main(String[] args) throws IOException {

        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");

        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<TableBlockResponse> sb = topj.getLastTableBlock(account, account.getAddress());
        String s = JSON.toJSONString(sb);
        System.out.println(s);
    }
}

Response Sample

{
  "data":{
    "value":{
      "body":{
        "tableblock":{
          "txs":[
            {
              "tx_consensus_phase":"send",
              "tx_hash":"0x4a334051b7a199af5694e9c5e2cbf6d1190de95148a9cf9ca0e9abf05b6857fb"
            }],
          "units":[
            {
              "account":"T00000LWxPzhvHkPifdEAHQnWijWkiVUtqzFdnZQ",
              "unit_height":4
            }]
        }
      },
      "hash":"a38b1f121383c56455eb0968aa2834e70e926f01d2ada5e1d1da3b2132f9c335",
      "header":{
        "auditor":"T00000LWi3nfReoWFHsXerSqhn7gCFLFW8L4YB71",
        "auditor_xip":"100000000000001:f60000ff00040401",
        "multisign_auditor":"740000005800000031f768bd00000000210003f5c142ecc0dc43e23ccbc30e4ac3b9c44a9dffe8fb619bc667a1b9b36668fc492000c426714873a81a28a8394d7fb111292879f60e262231f7943b565385a3ca5ef304000e",
        "multisign_validator":"740000005800000031f768bd00000000210003447276b3f8a80fcc098ca7c2751432b8b14b453647d66e905af1acaae5f028a720000ef592d465d52fd39c5d2c65b1e59c39e5432a68c033f0bd21fae7265d6dbef604000d",
        "timerblock_height":7684597,
        "validator_xip":"100000000000001:f60000ff000507ff",
        "version":"196608"
      },
      "height":46,
      "owner":"Ta0000@29",
      "prev_hash":"df46abed91fa9747142826f506921082fd10e59c09ab922d6dd03e4f4a69c2a5",
      "table_height":46,
      "timestamp":1650035170
    }
  },
  "errmsg":"OK",
  "errno":0,
  "sequence_id":"880646877990206582"
}

# Account Management

# Query Account Information On The Chain

The account’s latest "nonce" and "last_hash_xxhash64" are used When sending a transaction to the chain. These two attributes can be obtained from the return value of this method.

Request Method

topj.getAccount

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Parameters Name Parameter Type Description
account_addr String Normal user account address or contract account address.
available_gas Uint64 The available gas of the account address. The unit is Tgas.
If the return value is negative, there may be two reasons: 1. The account balance after obtaining free gas is less than 100*10^6 uTOP; 2. Unlock the TOP Token after running out the gas exchanged.
balance Uint64 The balance of the account address. The unit is uTOP.
burned_token Uint64 All burned TOP tokens of the account address. The unit is uTOP.
cluster_id Uint8 cluster ID。
created_time Uint64 The clock height when the account created on the blockchain.
disk_staked_token Uint64 The amount of locked TOP tokens to exchange disk. The unit is uTOP.
gas_staked_token Uint64 The amount of locked TOP tokens to exchange gas. The unit is uTOP.
group_id Uint8 group ID。
latest_tx_hash String The hash of the latest successful transaction.
latest_tx_hash_xxhash64 String The xx64hash of the latest successful transaction.
latest_unit_height Uint64 The unit block height of the latest successful transaction.
lock_balance Uint64 Locked TOP tokens used for application contract transactions. Unit of measurement is uTOP
When running applicaiton contract, the transaction sender can transfer TOP tokens to the contract account at the same time. If the contract fails to execute, the transferred TOP tokens needs to be returned to the sender. Therefore, the transferred money should be locked before running the contract successfully.
lock_gas Uint64 Application contract transaction costs are related to the CPU time and transaction size.The costs of the application contract transactions cannot be determined at the beginning of the transaction. The method adopted is to freeze part of the gas of the transaction sender. At the third round of consensus of the transaction, according to the final execution of the application contract, the gas of the sender is deducted to pay for the costs. Measured in Tgas.
nonce Uint64 The nonce of the latest successful transaction. Unique in the global network.
total_free_gas Uint64 Total free gas of the account address. Measured in Tgas.
At present, when the account balance ≥100*10^6 uTOP, the system will give the account 25,000 Tgas for free. This value changes along with the on-chain governance parameters changes.
total_gas Uint64 Total gas of the account address. Measured in Tgas.
total_stake_gas Uint64 Total gas obtained by locking TOP Tokens. Measured in Tgas.
unlock_disk_staked Uint64 TOP tokens to exchange disk in unlock. After initiating the unlock, we need to wait 24 hours for the unlocked amount to arrive in the account.
unlock_gas_staked Uint64 TOP tokens to exchange gas in unlock. After initiating the unlock, we need to wait 24 hours for the unlocked amount to arrive in the account.
unused_vote_amount Uint64 Unused vote amount of the account.
vote_staked_token Uint64 TOP tokens to exchange votes in lock.
zone_id Uint8 zone ID.
tableid Unit16 Table ID.
recv_tx_num Uint64 The number of transactions when the account is the receiver.

Shard to which the account belongs:

ID Shard
zone_id, cluster_id, group_id, are 1, 0, 0 Beacon Network
zone_id, cluster_id, group_id, are 2, 0, 0 Beacon Network
zone_id, cluster_id, group_id, are 14, 1, 1 Archive Network
zone_id, cluster_id, group_id, are 15, 1, 1 Edge Network
zone_id, cluster_id, are 0, 1, group_id∈[1,63] Audit Network
zone_id, cluster_id, are 0, 1, group_id∈[64,126] Validate Network

To query application contract account information, return the following two parameters in addition to the above parameters.

Parameter Name Parameter Name Description
contract_code String Application contract code.
contract_parent_account String Contract parent account that deployed the application contract.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.AccountInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetAccount {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 3));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        ResponseBase<AccountInfoResponse> accountInfoResponse = topj.getAccount(account);
        System.out.println(JSONObject.toJSON(accountInfoResponse));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"total_gas": 25138,
		"account_addr": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
		"unused_stake_gas": 138,
		"unlock_disk_staked": 0,
		"available_gas": 24390,
		"total_free_gas": 25000,
		"table_id": 3,
		"total_stake_gas": 138,
		"zone_id": 0,
		"cluster_id": 1,
		"balance": 199978600,
		"latest_unit_height": 10,
		"unlock_gas_staked": 4000,
		"gas_staked_token": 16000,
		"created_time": 1642066250,
		"disk_staked_token": 0,
		"unused_vote_amount": 0,
		"unused_free_gas": 24252,
		"nonce": 8,
		"latest_tx_hash": "0xab24e8aa4f93f0d2d450360c0ef11614998c275ccf1d32d39a5a22cc6f57db38",
		"burned_token": 0,
		"latest_tx_hash_xxhash64": "0xa5bfa37aa1edd3f5",
		"vote_staked_token": 0,
		"group_id": 64,
		"recv_tx_num": 2,
		"lock_balance": 4000
	},
	"sequence_id": "4533788721199354927",
	"errmsg": "OK"
}

# Transfer

Send TOP to another account address.

Request Method

topj.transfer

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Object Before sending the transaction, you need to get the latest nonce and last_hash_xxhash64, and assign them to the account object to be used. You can directly run the "topjs.updateNonceAndLastHash" method, and these two parameters will be automatically put into the account object.
to Yes - String The address of the transaction receiving account, either an ordinary account or a contract account.
The receiver address is in the "account_addr" attribute under the "target_action" object.
note No Empty String String Transfer note.
amount Yes - Uint64 Transfer amount. The unit is uTOP.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;
import java.math.BigInteger;

public class Transfer {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.transfer(account,"T80000bde88ffafff06e99f77b9c1e3db3f0d903597f93", BigInteger.valueOf(1400), "转账");
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@22",
				"height": 31
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 207
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 426,
				"account": "Ta0000@44",
				"height": 204
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "转账",
			"receiver_account": "T80000bde88ffafff06e99f77b9c1e3db3f0d903597f93",
			"premium_price": 0,
			"authorization": "0x007f584d661de5fd3973c0f461da3ddc8685c97d797788d7c1ec686cd39306e2a52d9e95ac469166e8e7890867b0e38138a165bcfd069d5bd7de1ce56b71779572",
			"from_ledger_id": 0,
			"send_timestamp": 1642228667,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 4,
			"ext": "",
			"amount": 1400,
			"tx_len": 142,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x21c05535fd63dc3f6fab717b61cb0bb8146daad8b8d57927e3c5d397d564916b",
			"last_tx_nonce": 24,
			"sender_action_param": "0x03000000544f507805000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x03000000544f507805000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 142,
	"sequence_id": "-7650297722120497985",
	"errmsg": "OK",
	"tx_hash": "0x21c05535fd63dc3f6fab717b61cb0bb8146daad8b8d57927e3c5d397d564916b"
}

# Query Transaction

Request Method

topj.getTransaction

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
txHash Yes - String Transaction hash.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class GetTransaction {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.getTransaction(account,"0xf6deeb9c5e46b379bae112a83bb9e4f3bdc14c63031e4ed7bdfa27f5dd0f7dff");
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

Different transaction information is returned according to the different status of the transaction, as follows.

If the transaction is a single-account transaction, there is only one round of consensus under the transaction sender. Only the information of "confirm_block_info" is returned in the result.

If the transaction is an across-account transaction, there are three rounds of consensus in total. The information of the three consensus, including "confirm_block_info (the second round of consensus under the sender) ", "recv_block_info(consensus under the receiver)" and "send_block_info" (the first round of consensus under the sender) are returned in the result.

  1. The transaction is in the block, but not in the transaction pool, and the transaction status is "confirmed", returning the original transaction information and all block information, as shown below.

    Determine whether the transaction is successful or not according to the parameter "exec_status":

    • When the value of exec_status is "success", it proves that the transaction is finally successful.

    • When the value of exec_status is "failure", the transaction fails. At this time, the value of recv_tx_exec_status is "failure", indicating that the consensus under the receiver is failed.

      {
      "errno":0,
      "data":{
          "tx_consensus_state":{
          "recv_block_info":{
              "used_gas":0,
              "account":"Ta0000@5",
              "height":165310
          },
          "confirm_block_info":{
              "used_deposit":0,
              "exec_status":"success",
              "recv_tx_exec_status":"success",
              "used_gas":0,
              "account":"Ta0000@4",
              "height":482333
          },
          "send_block_info":{
              "tx_fee":0,
              "used_deposit": 0,
              "used_gas":558,
              "account":"Ta0000@4",
              "height":482333
          }
          },
          "failure":false,
          "success":true,
          "original_tx_info":{
          "note":"subscription",
          "receiver_account":"T00000LRHtK4YRD7z8VJLW9s9mSw2sbxKUsyMjeP",
          "premium_price":0,
          "authorization":"0x0180cc4b53871be19ff816a4be82a62f8e29d34d53ecbaccf6eb2c7720286a5fc85db1229ff679330c5c729f3cee6ba43139423c5a14459810bdca4e5c5000d366",
          "from_ledger_id":0,
          "send_timestamp":1650972889,
          "token_name":"",
          "tx_random_nonce":0,
          "tx_type":4,
          "ext":"",
          "amount":1,
          "tx_len":186,
          "edge_nodeid":"",
          "tx_structure_version":2,
          "tx_hash":"0xb60a510ad25d95e39d29333f235dc8c097d15cdd96a381611df2ba35c61da1e9",
          "last_tx_nonce":5177,
          "sender_action_param":"{\"amount\":1,\"token_name\":\"TOP\"}",
          "last_tx_hash":"",
          "tx_deposit":100000,
          "sender_action_name":"",
          "tx_expire_duration":100,
          "receiver_action_param":"{\"amount\":1,\"token_name\":\"TOP\"}",
          "sender_account":"T00000LTc1yaVCqMH5g3DNKG9i3px13KmsJBbMkb",
          "to_ledger_id":0,
          "challenge_proof":"",
          "receiver_action_name":""
          }
        },
      "sequence_id":"5817967982351345580",
      "errmsg":"OK"
      }
      
  2. The transaction is both in the block and the transaction pool, and the transaction status is "queue". The original transaction information and some valid block information are returned by the query.

    As shown below, the transaction completes the first round of consensus and returns a valid information of "send_unit_info" when the second and third rounds of consensus have not yet been successful.

    {
    'original_tx_info': {
        'amount': 100,
        'authorization': '0x0000d616b2dc5f89af842910d59ce214f6341daf60068a87b387a9274f734b30e81d24f258189d4f52e7789d239065f021d3abaab23f2739e0a71001ac9c7b8b37',
        'edge_nodeid': '',
        'ext': '',
        'last_tx_nonce': 1,
        'note': 'test_app',
        'premium_price': 0,
        'receiver_account': 'T80000b871687e28e8d123937b80cb3fd19e72ff02729d',
        'receiver_action_name': '',
        'receiver_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'send_timestamp': 1651037348,
        'sender_account': 'T80000baf4619bd40a8ff7795170392d7a608069665a42',
        'sender_action_name': '',
        'sender_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'token_name': '',
        'tx_deposit': 100000,
        'tx_expire_duration': 100,
        'tx_hash': '0x60006ee3838a221463e40f45941053a3276a65417b4b88ba68337bb95c83934a',
        'tx_len': 143,
        'tx_structure_version': 2,
        'tx_type': 4
    },
    'tx_consensus_state': {
        'recv_block_info': {
        'height': None
        },
        'send_block_info': {
        'account': 'Ta0000@6',
        'height': 4,
        'tx_fee': 0,
        'used_deposit': 0,
        'used_gas': 429
        }
    },
    'tx_state': 'queue'
    }
    
  3. The transaction is not in the block, but in the transaction pool, the transaction status is "pending", only the original transaction information is returned, and the transaction consensus status is "null", as shown below.

    {
    'original_tx_info': {
        'amount': 100,
        'authorization': '0x0000d616b2dc5f89af842910d59ce214f6341daf60068a87b387a9274f734b30e81d24f258189d4f52e7789d239065f021d3abaab23f2739e0a71001ac9c7b8b37',
        'edge_nodeid': '',
        'ext': '',
        'last_tx_nonce': 1,
        'note': 'test_app',
        'premium_price': 0,
        'receiver_account': 'T80000b871687e28e8d123937b80cb3fd19e72ff02729d',
        'receiver_action_name': '',
        'receiver_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'send_timestamp': 1651037348,
        'sender_account': 'T80000baf4619bd40a8ff7795170392d7a608069665a42',
        'sender_action_name': '',
        'sender_action_param': {
        'amount': 100,
        'token_name': 'TOP'
        },
        'token_name': '',
        'tx_deposit': 100000,
        'tx_expire_duration': 100,
        'tx_hash': '0x60006ee3838a221463e40f45941053a3276a65417b4b88ba68337bb95c83934a',
        'tx_len': 143,
        'tx_structure_version': 2,
        'tx_type': 4
    },
    'tx_consensus_state': null,
    'tx_state': 'pending'
    }
    

# Lock TOP For Gas

Lock TOP For Gas

Request Method

topj.stakeGas

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
locked_utop Yes - Uint64 Locked TOP token. The unit is "uTOP".

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeGas {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeGas(account, BigInteger.valueOf(4000));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 151,
				"account": "Ta0000@3",
				"height": 58
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"premium_price": 0,
			"authorization": "0x0180fdea4bfdcf1dc7b7001fa3b632fc8adfe126e9bd9375ee343d904cc560fee53eeba47ba7f61fc7d34c40bc677e31635530dbd4618d25299c33bd1acdf545b6",
			"from_ledger_id": 0,
			"send_timestamp": 1642228333,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 22,
			"ext": "",
			"amount": 0,
			"tx_len": 151,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x8ff271442ed894a8f57cc6642ed8469584bf962252ddd32ada780c4cdc6ad4ea",
			"last_tx_nonce": 8,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000a00f000000000000",
			"sender_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 151,
	"sequence_id": "5460731776410679387",
	"errmsg": "OK",
	"tx_hash": "0x8ff271442ed894a8f57cc6642ed8469584bf962252ddd32ada780c4cdc6ad4ea"
}

# Unlock TOP For Gas

After initiating the unlock, you have to wait 24 hours and send a transaction (not a query) before the unlocked TOP tokens are received.

Request Method

topj.unStakeGas

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
unlocked_utop Yes - Uint64 Unlocked amount. The unit is "uTOP".

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;
import java.io.IOException;
import java.math.BigInteger;

public class UnStakeGas {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeGas(account, BigInteger.valueOf(2000));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 151,
				"account": "Ta0000@3",
				"height": 61
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"premium_price": 0,
			"authorization": "0x01dcd27457c0bafa4ea83a8b3aa3aaa66e5559a0fe5bf522673e22c889ecf990156dc05ff6473120dd19f7e501e1510d5f69923d7a134b1b5a92183b16c5cd0d31",
			"from_ledger_id": 0,
			"send_timestamp": 1642229760,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 23,
			"ext": "",
			"amount": 0,
			"tx_len": 151,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x97960b275c567ac65b8fad16d36da7378c333be92603eecc3ec86daa348aad02",
			"last_tx_nonce": 9,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000d007000000000000",
			"sender_account": "T80000e128cad9ff47826093b0f9ed6f479eed0f86c733",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 151,
	"sequence_id": "7557049805931304829",
	"errmsg": "OK",
	"tx_hash": "0x97960b275c567ac65b8fad16d36da7378c333be92603eecc3ec86daa348aad02"
}

# Miner Operations

# Register Miner

There are five types of miners in TOP Network: edge, validator, advance, archive, and exchange node. You can register as one of the first three types of miners.

Advance miner can serve as multiple nodes in different networks: validator and auditor.

The minimum registration deposit of each node is shown in the table below.

Node Type Minimum Registration Deposit
edge 100,000*10^6 uTOP token
validator 500,000*10^6 uTOP token
advance 1,000,000*10^6 uTOP token

Request Method

topj.registerNode

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
mortgage Yes - Uint64 Miner registration deposit, the unit is uTOP.
nodeType Yes - String There are five types of miners in TOP Network: edge, validator, advance, archive, and exchange node.
You can register as one of the first three types of miners.
After registering as an advance miner, what kind of node the mine is elected depends on the votes it receives:
If the advance miner is to be elected as auditor node, the votes must be greater than or equal to the actual registration deposit of the miner (Here, the node deposit is calculated by TOP, not uTOP).
When the votes falls below the actual staked deposit, the advance miner can only be elected as validator.
Caution:
Miner's votes must be voted by other nodes or by this node himself.
After registering as the advance miner, if you increase the miner deposit, the miner needs to increase the corresponding votes if it wants to be elected as auditor.
nickName Yes - String Miner nick name, 4-16 characters, letters, Numbers or underscores.
node_sign_key Yes - String The account key pair is used as node_sign_key by default.
It is recommended that you use a asset-free public-private key pair to protect your account assets better, the private key is used to sign the node when it is working after they have been elected into the network.
Please enter the corresponding public key (Base58), which can be used by other nodes for decryption.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.property.NodeType;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class RegisterNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        account.setAddress("T800005cb91f65f64f6247852a1419307a940ff507e362");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.registerNode(account, BigInteger.valueOf(1100000000000L), NodeType.advance, "topNode1", "238a2d2f4aae4b397d6604db54b6bb765e18a93e5f775d213e031383d9830142e078c088dd296f78d7dbdf43077dec6ca07e34c6d9fa5b4f1acf7773a237ea42", BigInteger.valueOf(20));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 216
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@8",
				"height": 103
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 1041,
				"account": "Ta0000@8",
				"height": 100
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x007743882dd2534e5d1c77873fee8281e84c7d9a78c688cd856989f219ce0cdb2b65ccb4156532f17f1a4407d35007a7d89e91fc991f2d4c420546cdc20359ee23",
			"from_ledger_id": 0,
			"send_timestamp": 1642406785,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 347,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x6b05f662add51d47ccff885085d03ffb6d3b117d8d9604740eb92ea0eb233a6d",
			"last_tx_nonce": 0,
			"sender_action_param": "0x0000000000f81b1d00010000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x07000000616476616e636508000000746f704e6f646531800000003233386132643266346161653462333937643636303464623534623662623736356531386139336535663737356432313365303331333833643938333031343265303738633038386464323936663738643764626466343330373764656336636130376533346336643966613562346631616366373737336132333765613432020000003230",
			"sender_account": "T800004ffdd1cec893a4d79eb2e97656378348618c847f",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "registerNode"
		}
	},
	"tx_size": 347,
	"sequence_id": "2835273932371462638",
	"errmsg": "OK",
	"tx_hash": "0x6b05f662add51d47ccff885085d03ffb6d3b117d8d9604740eb92ea0eb233a6d"
}

# Query Miner Information

Request Method

topj.queryNodeInfo

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
nodeAddress Yes - String Node account address.

Response Parameters

Parameter Name Parameter Type Description
account_addr String Miner account address.
auditor_credit String Auditor credit.
auditor_stake Uint64 Auditor stake: auditor stake=(miner deposit+vote amount/2)*auditor credit
dividend_ratio Integer Dividend ratio, percentage%, value[0,100]。
network_id String A value of 0 indicates that the node joins the mainchain network.
node_deposit Uint64 Miner registration deposit(uTOP).
nodename String Miner name.
registered_node_type String Registered miner type:
edge, validator, advance.
node_sign_key String Public key used in registering miner.
validator_credit String Validator credit.
validator_stake Uint64 Validator stake: validator stake=sqrt[(miner deposit+vote amount/2)*validator credit]
vote_amount Uint64 Total number of votes received from voting.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.NodeInfoResponse;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryNodeInfo {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<NodeInfoResponse> nodeInfo = topj.queryNodeInfo(account, account.getAddress());
        System.out.println("node info > " + JSON.toJSONString(nodeInfo));
    }
}

Response Sample

{
	"data": {
		"account_addr": "T800005cb91f65f64f6247852a1419307a940ff507e362",
		"auditor_credit": "0.330000",
		"auditor_stake": 166155033,
		"dividend_ratio": 2,
		"network_id": "255 ",
		"node_deposit": 3500000005000,
		"node_sign_key": "9bd05405d9c6363e5b1c70717623ae3f2c0a43b5d77d1a1310fdc54d205e614712cd89c6cf876453cee783af6a3c2b9c4b1632ce35f7b405de185ea5773e37c5",
		"nodename": "topNode1",
		"rec_stake": 503500100,
		"registered_node_type": "advance",
		"validator_credit": "0.330000",
		"validator_stake": 5000,
		"vote_amount": 1000000200,
		"zec_stake": 503500100
	},
	"errmsg": "OK",
	"errno": 0,
	"sequence_id": "7304676093041685078"
}

# Update Miner Type

Request Method

topj.updateNodeType

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
mortgage Yes - BigInteger Miner deposit.
nodeType Yes - String Miner type, all types are under the NodeType object.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.property.NodeType;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UpdateNodeType {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.updateNodeType(account, BigInteger.valueOf(1200000000000L), NodeType.advance);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 195
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 232
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 597,
				"account": "Ta0000@44",
				"height": 229
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x006707d83a7c5068468bf6abd3f2d2cc742cd02a86feb1e5e5663d39a218189ce409c3fedaa48b5b9d1a534a10a2a5e6cc7c07825ed6a8988c4730a5d965fd3dfd",
			"from_ledger_id": 0,
			"send_timestamp": 1642230017,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 199,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x8e166f73dae9d71898039f4ebb2a1fa5a74b50108f069be58794878afa018873",
			"last_tx_nonce": 27,
			"sender_action_param": "0x0000000000e092651701000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x0400000065646765",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "updateNodeType"
		}
	},
	"tx_size": 199,
	"sequence_id": "-2105626912941656979",
	"errmsg": "OK",
	"tx_hash": "0x8e166f73dae9d71898039f4ebb2a1fa5a74b50108f069be58794878afa018873"
}

# Set Miner Name

Request Method

topj.setNodeName

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
nickname Yes - String Miner nick name.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class SetNodeName {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.setNodeName(account, "nick2");
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 285
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 437
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 579,
				"account": "Ta0000@44",
				"height": 434
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x00c3cbbd11a126a781cf4049405f0c8fc585e2ad5c42c9fc3dd34abada260369e80b8ae1bac77fbc562d4b2eac2fc7cf57dca0feea2ef812a6c16ccdaaf924c4c0",
			"from_ledger_id": 0,
			"send_timestamp": 1642564755,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 193,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x966466ad79770ad50f6686b1273a59d77cd50ba795b241e2001478eb8ee20d9e",
			"last_tx_nonce": 46,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x050000006e69636b32",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "setNodeName"
		}
	},
	"tx_size": 193,
	"sequence_id": "-7844052753189848288",
	"errmsg": "OK",
	"tx_hash": "0x966466ad79770ad50f6686b1273a59d77cd50ba795b241e2001478eb8ee20d9e"
}

# Stake Deposit

You can increase the miner deposit to improve your comprehensive stake at any time.

Increasing the miner deposit does not change the type of miner you have registered.

Request Method

topj.stakeDeposit

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
mortgage Yes - BigInteger Increased miner deposit.

Response Parameter

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeDeposit(account, BigInteger.valueOf(5000));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 186
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 198
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 555,
				"account": "Ta0000@44",
				"height": 195
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x0088f7daebe286140811b55ec7c3dedbbcef9be0ee9a38d6a1281c4793e0517d2e1b365abeaa991dbf92c4849df6c462bbecd2a51a79796be29c114e7349146bde",
			"from_ledger_id": 0,
			"send_timestamp": 1642228256,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 185,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xb3f1f19fcde745cfa902e4f6619f01b07aea8120b36ad1732959547ecc420f6b",
			"last_tx_nonce": 22,
			"sender_action_param": "0x000000008813000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "stakeDeposit"
		}
	},
	"tx_size": 185,
	"sequence_id": "6811970780427338832",
	"errmsg": "OK",
	"tx_hash": "0xb3f1f19fcde745cfa902e4f6619f01b07aea8120b36ad1732959547ecc420f6b"
}

# Unstake Deposit

You can reduce the miner deposit at any time. Reducing the deposit will not change the type of miner you registered. But the reduction of the deposit will fail if the miner's deposit balance is lower than the minimum deposit requirement for the current type of miner.

Request Method

topj.unStakeDeposit

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
mortgage Yes - BigInteger Decreased miner deposit.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UnStakeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeDeposit(account, BigInteger.valueOf(3500));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 297
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 456
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 585,
				"account": "Ta0000@44",
				"height": 453
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x0086c83cd67b6ffa979d8f9e454a4876b49278efd2b8bb556d9daf4be8124b6c1717cef41ae49733f8fe2b0569fa4bc8f0eee052375ef5dd1261db7d7d8e8ea4e0",
			"from_ledger_id": 0,
			"send_timestamp": 1642566310,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 195,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x4b70fbcc055f548633ba575ad74cf0b78b67e1e72bcade9b4d9ad1d18cf10e6f",
			"last_tx_nonce": 49,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0xac0d000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unstakeDeposit"
		}
	},
	"tx_size": 195,
	"sequence_id": "-6110982047882771409",
	"errmsg": "OK",
	"tx_hash": "0x4b70fbcc055f548633ba575ad74cf0b78b67e1e72bcade9b4d9ad1d18cf10e6f"
}

# Set Dividend Ratio

Request Method

topj.setDividendRate

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
dividendRate Yes - BigInteger Dividend ratio∈ [0 ~ 100].

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class SetDividendRate {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.setDividendRate(account, BigInteger.valueOf(30));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 288
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 443
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 591,
				"account": "Ta0000@44",
				"height": 440
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x00e6f61a751f342ed4c83ee9a5f371de83a11ff68b9c515e9e0f96b6f68fba1faa7af66acdc59502dcbfbdd04bec20642fe82e702265c42f7e93672e5beaf652e6",
			"from_ledger_id": 0,
			"send_timestamp": 1642566017,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 197,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xcad5c6a13236e2150af3512a37a1df55f51e11b6cc268c388b2cfbae1c7d5ce2",
			"last_tx_nonce": 47,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x1e00000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "setDividendRatio"
		}
	},
	"tx_size": 197,
	"sequence_id": "1124612228439604214",
	"errmsg": "OK",
	"tx_hash": "0xcad5c6a13236e2150af3512a37a1df55f51e11b6cc268c388b2cfbae1c7d5ce2"
}

# List Votes Used

Request Method

topj.listVoteUsed

**Request Parameters **

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
voterAddress Yes - String Voter account address.

Response Parameters

Parameter Name Parameter Type Description
vote_infos Map Array Account address of node be voted(String); Amount of votes(Integer).

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.VoteUsedResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ListVoteUsed {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<VoteUsedResponse> result = topj.listVoteUsed(account, "T00000LWxPzhvHkPifdEAHQnWijWkiVUtqzFdnZQ");
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"vote_infos": {
			"T800005cb91f65f64f6247852a1419307a940ff507e362": 1000000000
		}
	},
	"sequence_id": "-3413557920370207769",
	"errmsg": "OK"
}

# Unregister Miner

The TOP Network miners need to unregister first before exiting the network.

  • Miner unregistration needs to initiate by the miner voluntarily.
  • After the unregistration , the miner registration deposit will not be immediately returned to the miner account and will be locked for a period of time.
  • After the expiration of the locked registration deposit, the miner shall redeem the deposit voluntarily, and the system will not automatically return it.

Request Method

topj.unRegisterNode

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class UnRegisterNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unRegisterNode(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0001@0",
				"height": 303
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 463
			},
			"send_block_info": {
				"tx_fee": 100000000,
                "used_deposit": 0,
				"used_gas": 573,
				"account": "Ta0000@44",
				"height": 460
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T2000138NZjvNJjRNG5iEqVKydpqAqoeNjBuFmNbj@0",
			"premium_price": 0,
			"authorization": "0x01e6fca2abb2fcfadf4bc8a042bf48e654cb0616fc59d75acd2fcbcd3820083c526486baf27567d39cd01dd812ed75efd6de6802181307a9c96259b1c636497521",
			"from_ledger_id": 0,
			"send_timestamp": 1642566442,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 3,
			"ext": "",
			"amount": 0,
			"tx_len": 191,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x41757c28579469b5f18334d6f8ca15a8f1e0e016a85e0fb7a62c2b9e7c1d855e",
			"last_tx_nonce": 50,
			"sender_action_param": "0x000000000000000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x00000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unregisterNode"
		}
	},
	"tx_size": 191,
	"sequence_id": "2061817932696966527",
	"errmsg": "OK",
	"tx_hash": "0x41757c28579469b5f18334d6f8ca15a8f1e0e016a85e0fb7a62c2b9e7c1d855e"
}

# Redeem Miner Deposit

After the unregistration , the miner registration deposit will not be immediately returned to the miner account and will be locked for 72 hours.

After the expiration of the locked registration deposit, the miner shall redeem the deposit voluntarily, and the system will not automatically return it.

Request Method

topj.redeemNodeDeposit

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class RedeemNodeDeposit {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("0x2d1352855059044465467a4e84382dbfab101074f8f2ea87dd356e3c29d3bc6d");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.redeemNodeDeposit(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01ace90aad93209164cc3976520d2393043b88e8ba151c69f4c0ff79caabd586b60cf5887b99db8cf3729e0e6e84d443ae3bc859fad75f44a1200d18e164db8258",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 5154942665457376997,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603783905,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "redeemNodeDeposit",
               "action_param" : "",
               "action_size" : 87,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138DSqqwBWkHKxkVuCq3htW47BGtJRCM2paf@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x22e076b89df6795434e8dc86460b5e6157642a906d83b1eec8d2fac1d522d9fd",
         "tx_len" : 312,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 10,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "b4d2d5ed1eb7a29a706eafaba69fded704a1b2155757598f9adec45eaa4d043e",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 11,
            "unit_hash" : "b14b2f771b6b8311fb6aa86288dd8069ad729ceccd355aa702c237de170684dc",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 9,
            "tx_fee" : 100000000,
            "unit_hash" : "73f642b73ec9bc7ac27032261d921b04dabb9fb6ab2561baa7ba2a9a928d1db5",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 936
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "51"
}

# staking

# Lock TOP For Votes

Rules for exchanging votes:

locked TOP token=votes_amount / [ 1.04^(lock_duration / 30 - 1) ], lock_duration<570;

locked TOP token=vote_amount / 2, lock_duration>=570。

The longer the lock duration is, the fewer TOP tokens are locked for the same number of votes.

Request Method

topj.stakeVote

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
amount Yes - Uint64 Amount of votes to be exchanged.
lockTime Yes - String TOP token lock duration. The the unit is "day".
The lock duration must be at least 30 days and must be an integer multiple of 30.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class StakeVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.stakeVote(account, BigInteger.valueOf(11000), BigInteger.valueOf(30));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "",
				"used_gas": 149,
				"account": "Ta0000@44",
				"height": 201
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"premium_price": 0,
			"authorization": "0x006f3f00f51f25db0b82b7f312205214cfa93e0cefecd5cfc76b2095fc3a61ceac148e3b8e8e209656f9430ec4c810848fe94745362e3c28e5b74d77dd6d8b2e25",
			"from_ledger_id": 0,
			"send_timestamp": 1642228383,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 27,
			"ext": "",
			"amount": 0,
			"tx_len": 149,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x6b53073a1e02a3ae87060968fb4c68aac3e87fa3d5675953952fe9a4a078c728",
			"last_tx_nonce": 23,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x4c040000000000001e00",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 149,
	"sequence_id": "3931658814308494287",
	"errmsg": "OK",
	"tx_hash": "0x6b53073a1e02a3ae87060968fb4c68aac3e87fa3d5675953952fe9a4a078c728"
}

# Unlock TOP For Votes

During the lock duration, the TOP tokens cannot be unlocked, only the TOP tokens at its expiry can be unlocked.

The TOP tokens that are locked corresponding votes that are already in use cannot be unlocked.

After initiating the unlock process, we have to wait 24 hours for the TOP token to return to the account.

Request Method

topj.unStakeVote

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
amount Yes - Uint64 Votes amount, unlock the corresponding TOP token.
note Yes - String Transaction note.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class UnStakeVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.unStakeVote(account, BigInteger.valueOf(1001));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x00dbb57645b28dc9261bc89c3b403f219c68b00da07d673d5ccb1930f042b8b75e62950579327682a79184e8cb502a5d9639a6d53e5293f52a47842ef965fdd98e",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 7288822057977092395,
         "last_tx_nonce" : 7,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603784708,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "0xce07000000000000",
               "action_size" : 74,
               "action_type" : 22,
               "tx_receiver_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 1,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x6245bed2227b7ff56d5bf6ae239685993f81b65990fe55f2b686e0d189ba50b1",
         "tx_len" : 299,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 28
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 13,
            "tx_exec_status" : "success",
            "unit_hash" : "c192c146d659f023a79eade70b513ec05def9e75a47f3309d7885f2f746fefd2",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 299
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "59"
}

# Vote for Miners

Please make sure that you have enough unused votes in your miner account before voting. You can use topj.getAccoun to query. If you do not have enough votes in your account, you can exchange votes by command topj.stakeVote.

Accounts on the block chain can vote for miners to obtain rewards:

  • An account can vote for up to 10,000 miners currently.

  • After voting on a miner, a portion of the reward won by the miner will be given to the voter.

Request Method

topj.voteNode

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Voter account object.
voteInfo Yes - Map<String, BigInteger> key: miner account address; value: votes number.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class VoteNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Map<String, BigInteger> voteInfo = new HashMap<>();
        String nodeAddress = "T800005cb91f65f64f6247852a1419307a940ff507e362";
        voteInfo.put(nodeAddress, BigInteger.valueOf(5000));
        ResponseBase<XTransactionResponse> result = topj.voteNode(account, voteInfo);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 282
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 285
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 684,
				"account": "Ta0000@44",
				"height": 279
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T20000MVfDLsBKVcy1wMp4CoEHWxUeBEAVBL9ZEa@44",
			"premium_price": 0,
			"authorization": "0x00f07f5b4e49f99d84e73ae36124b02b2512f61f6b41b0f9deb251d310c0deffde16273aa8692691ac0c58db56ddc549c89734b8bc976a145b8d7a43f4b5b0bf08",
			"from_ledger_id": 0,
			"send_timestamp": 1642230620,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 20,
			"ext": "",
			"amount": 0,
			"tx_len": 228,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0x3ec814a3e0be2da92aec5c885cb629c1ca67daa7a7263e340151b17456f433a0",
			"last_tx_nonce": 33,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x010000002e000000543830303030356362393166363566363466363234373835326131343139333037613934306666353037653336328813000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "voteNode"
		}
	},
	"tx_size": 228,
	"sequence_id": "4242996775985050247",
	"errmsg": "OK",
	"tx_hash": "0x3ec814a3e0be2da92aec5c885cb629c1ca67daa7a7263e340151b17456f433a0"
}

# Cancel Votes for Miners

A voter may cancel votes at any time that has already been vote on a miner.

The number of votes for each cancellation operation is unlimited, but cannot exceed the total number of votes vote on the nodes, otherwise the cancellation operation will fail.

After voting for the miner, even if the miner is unregistered, the votes will not be returned to your account. You need to initiate the cancellation operation.

You can cancel voting for miners in bulk.

Request Method

topj.unVoteNode

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Voter account address.
voteInfo Yes - Map<String, BigInteger> key: Miner account address; value: votes number.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

public class UnVoteNode {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Map<String, BigInteger> voteInfo = new HashMap<>();
        String nodeAddress = "T800005cb91f65f64f6247852a1419307a940ff507e362";
        voteInfo.put(nodeAddress, BigInteger.valueOf(100));
        ResponseBase<XTransactionResponse> result = topj.unVoteNode(account, voteInfo);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 219
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 222
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 690,
				"account": "Ta0000@44",
				"height": 216
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "",
			"receiver_account": "T20000MVfDLsBKVcy1wMp4CoEHWxUeBEAVBL9ZEa@44",
			"premium_price": 0,
			"authorization": "0x00cd2e3414a6bd09a57098b57466dfb19be3be78ed57ab1ba2e0d3374ca194420a0c9c5d7c765e5bc54c32396f1ffb9d7ee4f47e16084fb3780c7fa0f69d64f656",
			"from_ledger_id": 0,
			"send_timestamp": 1642229965,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 21,
			"ext": "",
			"amount": 0,
			"tx_len": 230,
			"edge_nodeid": "",
			"tx_structure_version": 2,
			"tx_hash": "0xbb654d3c3be4e0d64c071c6f5035ade858e04871c16e92bc21931dfe88694d04",
			"last_tx_nonce": 26,
			"sender_action_param": "",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x010000002e000000543830303030356362393166363566363466363234373835326131343139333037613934306666353037653336326400000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": "unvoteNode"
		}
	},
	"tx_size": 230,
	"sequence_id": "-2023431605716591646",
	"errmsg": "OK",
	"tx_hash": "0xbb654d3c3be4e0d64c071c6f5035ade858e04871c16e92bc21931dfe88694d04"
}

# Query Voter Dividend

After you vote on the miners, you can get the corresponding voting dividends, and the dividend ratio is set by the miners being voted.

Voter dividend is not immediately searchable and can be queried 6 hours after voting.

Request Method

topj.queryVoterDividend

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Voter account object.
nodeAddress Yes - String Voter account address.

Request Parameters

Parameter Name Parameter Type Description
accumulated Uint64 Total amount of voter dividend.The unit is uTOP.
last_claim_time Uint64 Clock height of the last time to claim voter dividend.
node_dividend List Dividend information of the miner.
account_addr String Account address of the miner.
accumulated Uint64 The dividend given to the voter by the miner. The unit is uTOP.
last_claim_time Uint64 The height of the clock at which the dividend of the miner was last claimed.
unclaimed Uint64 The unclaimed dividend given to the voter by the miner. The unit is uTOP.
unclaimed Uint64 The total amount of dividends the voter has not claimed. The unit is uTOP.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.VoterDividendResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryVoterDividend {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<VoterDividendResponse> result = topj.queryVoterDividend(account, account.getAddress());
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"node_dividend": [{
			"last_claim_time": 0,
			"account_addr": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"unclaimed": 144,
			"issue_time": 6896169,
			"unclaimed_decimals": 678682,
			"accumulated": 144,
			"accumulated_decimals": 678682
		}],
		"last_claim_time": 0,
		"unclaimed": 144,
		"issue_time": 6896169,
		"unclaimed_decimals": 678682,
		"accumulated": 144,
		"accumulated_decimals": 678682
	},
	"sequence_id": "1930283999220882257",
	"errmsg": "OK"
}

# Claim Voter Dividend

The system will issue voter dividends every 12 hours and automatically distribute voter dividends to the dividend pool.

The voter can apply for withdrawal once within 12 hours, and the withdrawal will be received immediately after the application is initiated.

Request Method

topj.claimVoterDividend

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Voter account object.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ClaimVoterDividend {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.claimVoterDividend(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x015e5aea769d3731c859ecccce438a9f32a38500c50601682ad1b0ce9d7adec60a216c460f52742e4000cd802cae7875058f77b2a71119012c00c36fadd5e11466",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 8346055492206021528,
         "last_tx_nonce" : 11,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603788080,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "claimVoterDividend",
               "action_param" : "",
               "action_size" : 84,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T20000MT3itmNbWs4XYn8R1NUcoucmppJwN7qE69@228"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x015ccae65496623557522ea5553db507f5c81ee854046d207f5cfd38bd04ab1d",
         "tx_len" : 309,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 21,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "52b68c8db349e20199be2afbe9e78938f1f31ea75e73695fac3e0dd8bf28f1d8",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 3,
            "unit_hash" : "20fac0960687f4d70ed4c124daa785891d3935377daae758d58240e94a9398ff",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 20,
            "tx_fee" : 0,
            "unit_hash" : "2e859716a101520de03ffd09181c64d8482f380fe6da959105d99ab1982d72db",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 927
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "86"
}

# Query Miner Reward

Query a single miner’s reward. Miner reward includes workload reward and votes reward.

Request Method

topj.queryNodeReward

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
nodeAddress Yes - String Miner account address.

Response Parameters

Parameter Name Parameter Type Description
accumulated Uint64 Total amount of miner reward. The unit is uTOP.
issue_time Uint64 The clock height when each miner's reward is issued.
last_claim_time Uint64 Clock height of the last time to claim miner reward.
unclaimed Uint64 Unclaimed reward. The unit is uTOP.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.NodeRewardResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<NodeRewardResponse> result = topj.queryNodeReward(account, account.getAddress());
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"last_claim_time": 0,
		"unclaimed": 1001933967,
		"issue_time": 6891868,
		"unclaimed_decimals": 793241,
		"accumulated": 1001933967,
		"accumulated_decimals": 793241
	},
	"sequence_id": "-4003021241813571072",
	"errmsg": "OK"
}

# Query All Miner Reward

Miner reward includes workload reward and votes reward.

Request Method

topj.queryAllNodeReward

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.

Response Parameters

Parameter Name Parameter Type Description
accumulated Uint64 Total amount of miner reward. The unit is uTOP.
issue_time Uint64 The clock height when each miner's reward is issued.
last_claim_time Uint64 Clock height of the last time to claim miner reward.
unclaimed Uint64 Unclaimed reward. The unit is uTOP.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.reward.NodeRewardResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.util.Map;

public class QueryAllNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<Map<String, NodeRewardResponse>> result = topj.queryAllNodeReward(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "T8000066ab344963eaa071f9636faac26b0d1a39900325" : {
         "accumulated" : 188072630515731,
         "accumulated_decimals" : 209604,
         "issue_time" : 3533760,
         "last_claim_time" : 0,
         "unclaimed" : 188072630515731,
         "unclaimed_decimals" : 209604
      },
      "T8000085a8e8acd53c72dca85dcb002a6710796975b4ba" : {
         "accumulated" : 135157655656316,
         "accumulated_decimals" : 441988,
         "issue_time" : 3533760,
         "last_claim_time" : 0,
         "unclaimed" : 135157655656316,
         "unclaimed_decimals" : 441988
      }
   },
   "errmsg" : "ok",
   "errno" : 0,
   "sequence_id" : "49"
}

# Claim Miner Reward

Miner reward can be received at most once every 12 hours.

Request Method

topj.claimNodeReward

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Miner account object.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class ClaimNodeReward {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.claimNodeReward(account);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01a28b0ed68e2ead15083616945a92e737be520eb73ab4bb8700d9e16b0f5d4d797068762f3fc5ea060064f5e0694b139a57a5cc96a898f60b2bcae2344b4f3775",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 2325913416141072335,
         "last_tx_nonce" : 4,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603797213,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "claimNodeReward",
               "action_param" : "",
               "action_size" : 81,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T20000MT3itmNbWs4XYn8R1NUcoucmppJwN7qE69@155"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T8000085a8e8acd53c72dca85dcb002a6710796975b4ba"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x92a7f8d2456d063ff772a97e4432481d28f9d2e9b3c876cf8e3ccbfa8cdf5c96",
         "tx_len" : 306,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 11,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "287bbf07214842d62c6239747c7168b941c46dbf6aa6e84d9de2b80668533cba",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 70,
            "unit_hash" : "00f4f97eaa3d080d05d6103540c4022f93789af7315db03505f71848fddb0d90",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 10,
            "tx_fee" : 0,
            "unit_hash" : "34ee08c46b7501a859f45bb057e58d8a1d2a73a26d2ca778dbcaed0892d2f751",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 918
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "26"
}

# Proposal

# Submit Proposals

When governing on the chain, you first need to submit an on-chain governance proposal.

Any user can submit a proposal as long as a certain TOP tokens are pledged.

In addition to the minimum transaction deposit of 100,000 uTOP token, the transaction fee of 100*10^6 uTOP token shall be deducted for running Beacon system contract transaction.

So make sure you have at least 100.1*10^6 uTOP balance in your account before submitting your proposal.

# On-Chain Governance Parameter Modification Proposals

Support the modification of Beacon transaction fees, account free gas, transaction margin and other On-chain Governance Parameters through proposals.

The system will issue governance rewards and zero workload rewards to the community fund account, community users can transfer these rewadrs to the burn account via community fund management proposal. Once the proposal has been voted through by TCC, the burn will take effect.

community fund account address: T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0.

burn account address: T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug.

Request Method

topj.submitProposal

Request Parameters

Parameter Name Required Default Value Parameter Type Description
proposal_type Yes - Uint8 Proposal Type:1--on-chain governance parameter modification proposal;2--community fund management proposal.
target Yes - String On-Chain Parameter Modification Proposal: Target is on-chain governance parameter, more about on-chain governance parameter please refer to On-Chain Governance Prarameters . Community Fund Management Proposal: Target is burn account address: target is T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug.
value Yes - String When target is on-chain governance parameter, value=new parameter value. When target is burn account address, value=transferd amount, the unit is uTOP.
proposal_deposit Yes - Uint64 Proposal deposit, current is "0".
effective_timer_height Yes - Uint64 Proposal effective clock height. If the clock height is less than the clock height at which the proposal was approved, the proposal will take effect immediately.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class SubmitProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> result = topj.submitProposal(account, BigInteger.valueOf(1), "T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug", "T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ua", BigInteger.valueOf(100000000L), BigInteger.valueOf(18400));
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x00055639267a80ec634048de50017a194407e092a849f3689fb4a907d4787ad3da3a0c99344f19366204a45cb4c0acd456d95a63f5c5671fc6e4efb75cd0591074",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 17353520882089532145,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1603797973,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "submitProposal",
               "action_param" : "0x0d0000006d696e5f766f7465735f6e756d010000003101e803000000000000",
               "action_size" : 115,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "0x0000000000e1f50500000000",
               "action_size" : 78,
               "action_type" : 0,
               "tx_sender_account_addr" : "T80000fd4f433c036268f17a1b4204ea907e70618d030e"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x7d46fcbf2932605d06a83249a73843f2429b7f681fb3a1b39aff6d5378c557e6",
         "tx_len" : 352,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 14,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "92e0cc560569c3fef734e30e228528d59dbed054b68964dd9fb5e1c358acb82f",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 54,
            "unit_hash" : "80bb6ada286f4ffc1235fef5151a82ff8fad78ee797af6d064d0827d60827d90",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 13,
            "tx_fee" : 100000000,
            "unit_hash" : "c9aadf4688b1bce6337ffd77b1ef06edb148cda682e7b5cac750bb8e4064c5bb",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 1056
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "31"
}

# Withdraw Proposal

A proposal can only be withdrawn by it's sponsor.

Request Method

topj.withdrawProposal

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
proposalId Yes - String Proposal ID.

Response Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class WithdrawProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        ResponseBase<XTransactionResponse> result = topj.withdrawProposal(account, proposal.getProposalId());
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x01cea8b3328ae1bc2c4ced3a584d2acb895938754859e46a89fbdd954e2488947e12ab0732457ed9ccfc91e2ba23bee2e1b96df3d8c6625143a33c6353d897fe9b",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 1339320303636985063,
         "last_tx_nonce" : 5,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1604047180,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "withdrawProposal",
               "action_param" : "0x0100000031",
               "action_size" : 91,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0xbeb7b03488646c051485b5979cba9ab2c30a75d568677c30182d1db932fa4763",
         "tx_len" : 316,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 9,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "0392946766b6a9908afb1950a71d9e25ede336d3bfb18bd8c5afc23c197acd76",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 2,
            "unit_hash" : "2326f7ff4d666fbc1a21125ccd90d11f36db47ef8f2eb4938a13155418b25b4a",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 8,
            "tx_fee" : 100000000,
            "unit_hash" : "a310bca7c898a0417fc34730a1e22595d3f2c5186f133a4018105e28faaa79a6",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 948
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "27"
}

# Query Proposal

Request Method

topj.queryProposal

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Account object.
proposalId Yes - String Proposal ID.

Response Parameters

Parameter Name Parameter Type Description
effective_timer_height Uint64 Proposal effective clock height. If the clock height is less than the clock height at which the proposal was voted through, the proposal will take effect immediately.
expire_time String Proposal expiration time. If the proposal is not approved or rejected by TCC within 259,200 clock height, the proposal will become invalid.
priority Uint8 Proposal priority: 1--Normal;2--Important;3--Critical. Only the TCC members have the right to vote on a proposal.
proposal_account_addr String The account address of the initiator of proposal.
proposal_deposit Uint64 Proposal deposit, the minimum is 100*10^6 uTOP.
proposal_id String Proposal ID, automatically generated by the system, unique.
proposal_type Uint8 Proposal Type: 1--on-chain parameter modification proposal;2--community fund management proposal.
target String On-Chain Governance Parameter Modification Proposal: Target is on-chain governance parameter, more about on-chain governance parameter please refer to On-Chain Governance Prarameters. Community Fund Management Proposal: Target is burn account address: T!0001Ebj8hBvoLdvcEEUwNZ423zM3Kh9d4nL1Ug.
value String When target is on-chain governance parameter,value=new parameter value. When target is burn account address,value=transfer amount, the unit is uTOP.
voting_status Uint16 Voting status of the proposal: 0-- not begun; 8-- In progress; 9 - failure; 10 - success.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class QueryProposal {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);

        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        ResponseBase<Proposal> result = topj.queryProposal(account, proposal.getProposalId());
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
    "data" : {
      "1":{
	      "effective_timer_height": 1010110,
	      "expire_time": 1000
	      "priority": 3,
	      "proposal_deposit": 400,
	      "proposal_id": 1,
	      "proposal_type": 1,
         "proposer_account_addr" : "T80000fd4f433c036268f17a1b4204ea907e70618d030v",
	      "target": archive_deposit,
	      "value": 1000,
	      "voting_status": 0
      }
   },
   "errmsg" : "ok",
   "errno" : 0,
   "sequence_id" : "3"
}

# TCC Vote On Proposals

You can get detailed information about the proposal before you vote on a proposal.

Only the TCC members have the right to vote on a proposal. Rules for voting on proposals:

The approval of 2/3 of the members is required, and no more than 1/5 of the opposition members.

After the proposal is voted through, a legislative order will be formed and sent to all nodes of the network.

After a proposal is voted through, the system will automatically delete the proposal, unable to query the proposal.

Request Method

topj.tccVote

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - Account Voter account object.
proposalId Yes - String Proposal ID.
proposalClientAddress Yes - String Proposer account address.
option Yes - Boolean Voting opinion: true or false.

Request Parameters

Please refer to Description of Transaction Body Object.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSONObject;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.Model.Proposal;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;

public class TccVote {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        Proposal proposal = new Proposal();
        proposal.setProposalId("sss");
        String clientAddress3 = "T80000fd4f433c036268f17a1b4204ea907e70618d030e";
        ResponseBase<XTransactionResponse> result = topj.tccVote(account, proposal.getProposalId(), clientAddress3, true);
        System.out.println(JSONObject.toJSON(result));
    }
}

Response Sample

{
   "data" : {
      "original_tx_info" : {
         "authorization" : "0x011ba5097a4b5a1f54776ec20bf2ca002fe259c51ff9f72a36882e1985239008e97ac8d49d12f768c1a2abadaf3b5e368a4ffeb6ab64c68f323192155fd1116409",
         "challenge_proof" : "",
         "ext" : "",
         "from_ledger_id" : 0,
         "last_tx_hash" : 11205396108775716568,
         "last_tx_nonce" : 6,
         "note" : "",
         "premium_price" : 0,
         "send_timestamp" : 1604050651,
         "to_ledger_id" : 0,
         "tx_action" : {
            "receiver_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "tccVote",
               "action_param" : "0x010000003501",
               "action_size" : 83,
               "action_type" : 5,
               "tx_receiver_account_addr" : "T2000138QMHWxXshXyZa1E48JU1LREu3UrT5KGD2U@0"
            },
            "sender_action" : {
               "action_authorization" : "",
               "action_ext" : "",
               "action_hash" : 0,
               "action_name" : "",
               "action_param" : "",
               "action_size" : 66,
               "action_type" : 0,
               "tx_sender_account_addr" : "T800002276a7d58218ac4978733e5cca927a7d86cb7c87"
            }
         },
         "tx_deposit" : 100000,
         "tx_expire_duration" : 100,
         "tx_hash" : "0x3ba14855d285087e60f257f703c1b9f070afa7d1a81c05a5662b4a2fe9f0320e",
         "tx_len" : 308,
         "tx_random_nonce" : 0,
         "tx_structure_version" : 2,
         "tx_type" : 3
      },
      "tx_consensus_state" : {
         "confirm_unit_info" : {
            "exec_status" : "success",
            "height" : 14,
            "recv_tx_exec_status" : "success",
            "tx_exec_status" : "success",
            "unit_hash" : "540746c16ac538de15f3d1f1a734ead7576fbd94dd99a5b8e5706efbe3aa49b5",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "recv_unit_info" : {
            "height" : 452,
            "unit_hash" : "5089993bf9ea2c74e5d82fd6ab19fa0dd13a56b7e506abd17aca2645f655f21e",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 0
         },
         "send_unit_info" : {
            "height" : 13,
            "tx_fee" : 100000000,
            "unit_hash" : "113cd7f87440097999b01e54aba194d94d8784bba49f3cd4b40f86a05c10fa78",
            "used_deposit" : 0,
            "used_disk" : 0,
            "used_gas" : 924
         }
      }
   },
   "errmsg" : "OK",
   "errno" : 0,
   "sequence_id" : "11"
}

# Tools

# Parse Out The amount and note In The Transfer Transaction Body

Parse out the "amount" and "note" in the transfer transaction body and assign them to the "TransferActionParam" object.

Request Method

TransferActionParam.decode

Request Parameters

Parameter Name Required Default Value Parameter Type Description
actionParam Yes - String Action parameters.

Response Parameters

None.

Request Sample

package org.sawyer;

import org.topj.account.Account;
import org.topj.core.Topj;
import org.topj.methods.Model.TransferActionParam;
import org.topj.methods.response.ResponseBase;
import org.topj.methods.response.tx.XTransactionResponse;
import org.topj.procotol.http.HttpService;
import org.topj.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class main {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://192.168.50.26:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("ec8519c723649ab2170807d39a9d01be1a6197266cfe39b4cc66c0433df85321");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> transferResponseBase = topj.transfer(account,"T800002276a7d58218ac4978733e5cca927a7d86cb7c87", BigInteger.valueOf(140), "hello top");
        TransferActionParam transferActionParam = new TransferActionParam();
        transferActionParam.decode(transferResponseBase.getData().getOriginalTxInfo().getReceiverAction().getActionParam());
    }
}

Response Sample

None.

# Check Whether The Transaction Is Successful

Request Method

topj.getTxStatus

Take the transfer transaction as an example:

  • Get XTransaction object and transaction hash from transaction object;
  • Call topj.getTxStatus(), "success" means the transaction is successful, "failure" means the transaction is failed; "pending" means the transaction is still being executed, "null means the transaction cannot be found.

Request Parameters

Parameter Name Required Default Value Parameter Type Description
account Yes - String Account address.
txHash Yes - String Transaction hash.

Response Parameters

Parameter Name Parameter Type Description
data
tx_consensus_state Object Transaction consensus status.
There will be three consensuses for cross-account transactions, so the information of three units will be returned; single-account transactions will only have one consensus under the transaction sending account, so only "confirm_block_info" will be returned.
recv_block_info Object The information of the table block that packages the recv transaction.
used_gas Uint32 For user contract transactions, the gas that should be deducted from the receiver's account after the second round consensus. The unit is Tgas.
account String Table address.
height Uint64 The height of the unit block which is generated in the second round consensus.
confirm_block_info Object The information of the table block that packages the confirm transaction.
used_deposit Uint32 After the third round consensus, the transaction deposit deducted from the sender's account when the sender's gas is not enough. The unit is uTOP.
exec_status String The consensus result of transaction sender: success or failure.
recv_tx_exec_status String The consensus result of transaction sender: success or failure.
used_gas Uint32 For user contract transactions, the gas that deducted from the sender's account after the third round consensus. The unit is Tgas.
If the contract account has paid part of the gas, then the rest of the whole gas consumed by the transaction is deducted here after this round of consensus; If the contract account is unable to pay its share of gas, all the gas consumed by the transaction is deducted here.
account String Table address.
height The height of the table block where the confirm transaction is located.
send_block_info Object The information of the table block that packages the send transaction.
tx_fee Uint64 For running Beacon system contract (miner registration related, proposal related, starting node process), the system will automatically deduct 100*10^6 uTOP tokens from the transaction sender's account as the transaction fee and burn it.
used_deposit Uint64 The transaction deposit consumed by the sending transaction.
used_gas Uint32 The gas deducted after the first round consensus. The unit is Tgas.
For cross-account transactions that do not run application contract, the gas consumed by the transaction shall be borne by the sender. If the sender account gas is sufficient, the gas required by the transaction will be deducted after the first round consensus. If the sender account gas is insufficient, the system will deduct all the gas available in the sender's account after first round consensus, and deduct the sender transaction deposit to exchange for gas to pay the remaining cost after the third round consensus.
account String Table address.
height Uint64 The height of the table block where the send transaction is located.
failure String Transaction execution faied.
success String Transaction execution succeeded.
original_tx_info Object Original transaction information.
note String Transaction notes.
receiver_account String The account address of the transaction receiver.
premium_price Uint32 Reserved field, defaults to "0".
authorization String Transaction body signature.
from_ledger_id Uint16 Reserved field, defaults to "0".
send_timestamp Uint64 Transaction send timestamp.
token_name String Token symbol, such as top is for TOP.
tx_random_nonce Uint64 Random numbers, defaults to "0". Not used yet.
tx_type Uint16 Transaction type. Different transaction types have different action param and action type in action.
xtransaction_type_run_contract = 3, // Run contract
xtransaction_type_transfer = 4, // Transfer
xtransaction_type_vote = 20, // Vote for miners
xtransaction_type_abolish_vote = 21, // Cancel votes for miners
xtransaction_type_pledge_token_gas = 22, // Lock TOP to get gas
xtransaction_type_redeem_token_gas = 23, // Unlock the TOP used to get gas
xtransaction_type_pledge_token_vote = 27, // Lock TOP to get votes
xtransaction_type_redeem_token_vote = 28, // Unlock the TOP used to get votes
ext String Reserved field for extension, defaults to an empty String.
amount String Table address.
tx_len Uint16 Transaction length. The gas consumed by a transaction is related to the transaction size.
edge_nodeid String Edge node id.
tx_structure_version Uint32 Transaction structure version, defaults to "2", Not used yet.
tx_hash String The hexadecimal of the transaction hash.
last_tx_nonce Uint32 The last transaction nonce.
sender_action_param String The transaction sender action. For the parameter serialization of different actions,please refer to Action Param Serialization.
last_tx_hash Uint64 The xx64hash of the transaction sender's last transaction, used for transaction sorting and deduplication.
tx_deposit Uint32 Transaction deposit. The unit is uTOP.
sender_action_name String Reserved field, defaults to an empty String.
tx_expire_duration Uint16 The expiration time of the transaction. If it exceeds, the transaction will be discarded. It defaults to 100s.
receiver_action_param String The transaction receiver action. For the parameter serialization of different actions,please refer to Action Param Serialization.
sender_account String Account address of the transaction sender.
to_ledger_id Uint16 Reserved field, defaults to "0".
challenge_proof String Reserved field, defaults to an empty String.
receiver_action_name String The name of contract function.
For system contract function,please refer to Platform Smart Contract API. For non-contract transactions, it defaults to an empty string.
tx_size String Transaction size.
sequence_id String The number of client sessions, incremented.
errmsg String Error message.
tx_hash String The hexadecimal of the transaction hash.

Request Sample

package org.topnetwork;

import com.alibaba.fastjson.JSON;
import org.topnetwork.account.Account;
import org.topnetwork.core.Topj;
import org.topnetwork.methods.response.ResponseBase;
import org.topnetwork.methods.response.tx.XTransactionResponse;
import org.topnetwork.procotol.http.HttpService;
import org.topnetwork.tx.PollingTransactionReceiptProcessor;

import java.io.IOException;
import java.math.BigInteger;

public class GetTxStatus {
    private static Topj topj = null;
    private static Account account = null;
    public static void main(String[] args) throws IOException {
        HttpService httpService = new HttpService("http://161.35.98.159:19081");
        topj = Topj.build(httpService);
        topj.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(5000, 10));
        account = topj.genAccount("2e912c20dfc43f4d37b1c9de86c557e104000efff0ba9eb780392a6bb329b368");
        topj.passport(account);
        topj.getAccount(account);
        ResponseBase<XTransactionResponse> transferResponseBase = topj.transfer(account,"T00000LZYyjZmvB7ZDXpDQqC9feE18o3cSFjL82Q", BigInteger.valueOf(140), "hello top");
        String txHash = transferResponseBase.getData().getOriginalTxInfo().getTxHash();
        String isSuccess = topj.getTxStatus(account, txHash);
        System.out.println("transfer hash >> " + txHash + " >> is success > " + isSuccess);
        System.out.println(JSON.toJSON(transferResponseBase));
    }
}

Response Sample

{
	"errno": 0,
	"data": {
		"tx_consensus_state": {
			"recv_block_info": {
				"used_gas": 0,
				"account": "Ta0000@1",
				"height": 90
			},
			"confirm_block_info": {
				"used_deposit": 0,
				"exec_status": "success",
				"recv_tx_exec_status": "success",
				"used_gas": 0,
				"account": "Ta0000@44",
				"height": 174
			},
			"send_block_info": {
				"tx_fee": 0,
                "used_deposit": 0,
				"used_gas": 492,
				"account": "Ta0000@44",
				"height": 171
			}
		},
		"failure": false,
		"success": true,
		"original_tx_info": {
			"note": "hello top",
			"receiver_account": "T00000LZYyjZmvB7ZDXpDQqC9feE18o3cSFjL82Q",
			"premium_price": 0,
			"authorization": "0x009ee17001b9006147e9a33852c1595ad9e363757e4cd9fc09060874dba0c6f0036e84566f6a842890f24046f3143f73c891b3d5901a31957797e2a6a2f9776aa4",
			"from_ledger_id": 0,
			"send_timestamp": 1642150847,
			"token_name": "",
			"tx_random_nonce": 0,
			"tx_type": 4,
			"ext": "",
			"amount": 140,
			"tx_len": 164,
			"edge_nodeid": "",
			"tx_structure_version" : 2,
			"tx_hash": "0xeccb83f4345a9fc037c9946bf0f7c4ba859a0af048407dc7b7adcf2ede410846",
			"last_tx_nonce": 21,
			"sender_action_param": "0x03000000544f508c00000000000000",
			"last_tx_hash": "",
			"tx_deposit": 100000,
			"sender_action_name": "",
			"tx_expire_duration": 100,
			"receiver_action_param": "0x03000000544f508c00000000000000",
			"sender_account": "T800005cb91f65f64f6247852a1419307a940ff507e362",
			"to_ledger_id": 0,
			"challenge_proof": "",
			"receiver_action_name": ""
		}
	},
	"tx_size": 164,
	"sequence_id": "-4567257279157316188",
	"errmsg": "OK",
	"tx_hash": "0xeccb83f4345a9fc037c9946bf0f7c4ba859a0af048407dc7b7adcf2ede410846"
}

# Transaction Body Data Structure

{
    "data":{
        "original_tx_info":{
            "authorization":"0x01aefd0a118c48fd7846f3ee05a2728a55141ebf3fe94e6076cd1fd1bef295140f356bb10a12dd6731d8ab50332d57ced26f6379162d0eb8fd87871603d8380056",
            "challenge_proof":"",
            "ext":"",
            "from_ledger_id":0,
            "last_tx_hash":"11448926042541027033",
            "last_tx_nonce":3,
            "note":"",
            "premium_price" : 0,
            "receiver_action":{
                "action_authorization":"",
                "action_ext":"",
                "action_hash":0,
                "action_name":"registerNode",
                "action_param":"0x040000006564676508000000746f704e6f6465310a0000007075626c6963206b6579",
                "action_size":116,
                "action_type":5,
                "tx_receiver_account_addr":"T2000138DSqqwBWkHKxkVuCq3htW47BGtJRCM2paf@0"
            },
            "send_timestamp":1600766121,
            "sender_action":{
                "action_authorization":"",
                "action_ext":"",
                "action_hash":0,
                "action_name":"",
                "action_param":"0x000000000010a5d4e800000000000000",
                "action_size":82,
                "action_type":0,
                "tx_sender_account_addr":"T8000066ab344963eaa071f9636faac26b0d1a39900325"
            },
            "to_ledger_id":0,
            "tx_deposit":300000,
            "tx_expire_duration":100,
            "tx_hash":"0x4ce54b11e728fbd65745873a9e831d39516fd0ea326ef055de76a9efd8d25783",
            "tx_len":357,
            "tx_random_nonce":0,
            "tx_structure_version" : 2,
            "tx_type":3,
            "xx64Hash":"0xa1b759352d90776c"
        },
        "tx_consensus_state":{
            "confirm_unit_info":{
                "exec_status":"",
                "height":0,
                "tx_exec_status":"",
                "unit_hash":"f45195cc04590c98aa12d8676bd5585de291620e1b76377ec46d0f1d8376a302",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":0
            },
            "recv_unit_info":{
                "height":3,
                "unit_hash":"b76a433d5a53392cd811f4d2ae06f357c49fd89cf97efdb955033723aaea1c4f",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":0
            },
            "send_unit_info":{
                "height":6,
                "tx_fee":100000000,
                "unit_hash":"a39ef9be02b3c301f50aeeddc1c474871f47104dbc4ef063fda9892a51dc99b3",
                "used_deposit":0,
                "used_disk":0,
                "used_gas":1071
            }
        }
    },
    "errmsg":"ok",
    "errno":0,
    "sequence_id":"1600766121429"
}

# Description of Transaction Body Object

Parameter Name Parameter Type Description
data
tx_consensus_state Object Transaction consensus status.
There will be three consensuses for cross-account transactions, so the information of three units will be returned; single-account transactions will only have one consensus under the transaction sending account, so only "confirm_unit_info" will be returned.
recv_block_info Object The information of the table block that packages the recv transaction.
used_gas Uint64 For user contract transactions, the gas that should be deducted from the receiver's account after the second round consensus. The unit is Tgas.
account String Table address.
height Uint64 The height of the table block where the receive transaction is located.
confirm_block_info Object The information of the table block that packages the confirm transaction.
used_deposit Uint64 After the third round consensus, the transaction deposit deducted from the sender's account when the sender's gas is not enough. The unit is uTOP.
exec_status String Final consensus result of the transaction: success or failure.
recv_tx_exec_status String The consensus result of transaction receiver: success or failure.
The consensus of the transaction receiver fails or refuses to execute. Consensus rejection usually happens during the contract transaction is being executed. For example, when registering a miner, if the miner's deposit is lower than the minimum requirement, the contract will fail to execute.
used_gas Uint64 For user contract transactions, the gas that deducted from the sender's account after the third round consensus. The unit is Tgas.
If the contract account has paid part of the gas, then the rest of the whole gas consumed by the transaction is deducted here after this round of consensus; If the contract account is unable to pay its share of gas, all the gas consumed by the transaction is deducted here.
account String Table address.
height Uint64 The height of the table block where the confirm transaction is located.
send_block_info Object The information of the table block that packages the send transaction.
tx_fee Uint64 For running Beacon system contract (miner registration related, proposal related, starting node process), the system will automatically deduct 100*10^6 uTOP tokens from the transaction sender's account as the transaction fee and burn it.
used_deposit Uint64 The transaction deposit consumed by the sending transaction.
used_gas Uint64 The gas deducted after the first round consensus. The unit is Tgas.
For cross-account transactions that do not run application contract, the gas consumed by the transaction shall be borne by the sender. If the sender account gas is sufficient, the gas required by the transaction will be deducted after the first round consensus. If the sender account gas is insufficient, the system will deduct all the gas available in the sender's account after first round consensus, and deduct the sender transaction deposit to exchange for gas to pay the remaining cost after the third round consensus.
account String Table address.
height Uint64 The height of the table block where the send transaction is located.
failure String Transaction execution failed.
success String Transaction execution succeeded.
original_tx_info Object Original transaction information.
note String Transaction notes.
receiver_account String The account address of the transaction receiver.
premium_price Uint32 Reserved field, defaults to "0".
authorization String Transaction body signature.
from_ledger_id Uint16 Reserved field, defaults to "0".
send_timestamp Uint64 Transaction send timestamp.
token_name String Token symbol, such as top is for TOP.
tx_random_nonce Uint32 Random numbers, defaults to "0". Not used yet.
tx_type Uint16 Transaction type. Different transaction types have different action param and action type in action.
xtransaction_type_run_contract = 3, // Run contract
xtransaction_type_transfer = 4, // Transfer
xtransaction_type_vote = 20, // Vote for miners
xtransaction_type_abolish_vote = 21, // Cancel votes for miners
xtransaction_type_pledge_token_gas = 22, // Lock TOP to get gas
xtransaction_type_redeem_token_gas = 23, // Unlock the TOP used to get gas
xtransaction_type_pledge_token_vote = 27, // Lock TOP to get votes
xtransaction_type_redeem_token_vote = 28, // Unlock the TOP used to get votes
ext String Reserved field for extension, defaults to an empty String.
amount Uint64 Transaction amount.
tx_len Uint16 Transaction length. The gas consumed by a transaction is related to the transaction size.
edge_nodeid String The edge node id that forwards the transaction, currently unused.
tx_structure_version Uint32 Transaction structure version, defaults to "2".
tx_hash String The hexadecimal of the transaction hash.
last_tx_nonce String The last transaction nonce.
sender_action_param String The transaction sender action. For the parameter serialization of different actions,please refer to Action Param Serialization.
last_tx_hash Uint64 The xx64hash of the transaction sender's last transaction, used for transaction sorting and deduplication.
tx_deposit Uint32 Transaction deposit. The unit is uTOP.
sender_action_name String Reserved field, defaults to an empty String.
tx_expire_duration Uint16 The expiration time of the transaction. If it exceeds, the transaction will be discarded. It defaults to 100s.
receiver_action_param String The transaction receiver action. For the parameter serialization of different actions,please refer to Action Param Serialization.
sender_account String Account address of the transaction sender.
to_ledger_id Uint16 Reserved field, defaults to "0".
challenge_proof String Reserved field, defaults to an empty String.
receiver_action_name String The name of contract function.
The system smart contract function,please refer to Platform Smart Contract API.
sequence_id String The number of client sessions, incremented.
errmsg String Error message.
errno Uint64 Error code.

# Code Sample

Contract code sample:

function init()
    create_key('temp_1')
    create_key('temp_2')
    hcreate('hmap')
    set_key('temp_1', '0')
    set_key('temp_2', '0')
    hset('hmap', 'key', 'val')
    hcreate('empty_map')
    create_key('map_len')
    create_key('map_str')

    lcreate('mlist')
    rpush('mlist', '44')
end

function opt_map(key, value)
    hset('hmap', toText(key), toText(value))
    lpush("mlist", toText(value))
end

function check_map(key)
    local map_len = hlen('hmap')
    set_key('temp_1', toText(map_len))
    local map_str = hget('hmap', toText(key))
    set_key('temp_2', toText(map_str))
    hdel('hmap', toText(key))
end

function get_empty_map()
    set_key('map_len', toText(hlen('empty_map')))
    set_key('map_str', toText(hget('empty_map', 'unexist')))
end

function get_empty_key()
    set_key('map_str', toText(hget('empty_map', '')))
end

function del_empty_key()
    hdel('hmap', '')
    set_key('map_len', toText(hlen('empty_map')))
end

function del_not_exist_key()
    hdel('hmap', 'unexist')
    set_key('map_len', toText(hlen('empty_map')))
end