# XWC Exchange Wallet Adaptation Guide

This chapter will introduce how the exchange adapts to XWC

# System environment hardware and software requirements

  • Operating system: Ubuntu 16.04 LTS64 bit system
  • Hardware: 16GB of memory + 10GB+ of available hard disk space

Exchanges and other centralized application systems access the underlying wallet through rpc

# How to start RPC server monitoring

Start RPC mode

  1. Start xwc_node --data-dir=$data-dir --rpc-enpoint=$server_ip
  2. Start xwc_client --wallet-file=$walletname --server-rpc-endpoint=$server_ip --rpc-endpoint=$client_ip
parameter Explanation
--data-dir Specify the data directory needed for xwc startup
--rpc-endpoint Specify xwc_node and xwc_client rpc listening ip port
--server-rpc-endpoint Specify the server ip that xwc_client needs to link to (the format is "ws://127.0.0.1:8090")
--wallet-file The specified wallet file, if not specified, the wallet will be automatically generated

Examples:

    xwc_node --data-dir =./data --rpc-endpoint=127.0.0.1:9991
    xwc_client --wallet-file=a.json --server-rpc-endpoint=”ws://127.0.0.1:9991” --rpc-endpoint=”127.0.0.1:9992”

The --rpc-endpoint parameter 127.0.0.1:9992 is the rpc entry point for users to access the xwc node

# RPC usage specification

How to use

All RPC interfaces follow the jsonrpc specification 2.0, specific reference documents:https://www.jsonrpc.org/specification

How to use

All jsonrpc data is passed through the HTTP POST method, and the results are obtained in the HTTP response. The URL of the HTTP request is the rpc monitoring service of xwc_client:http://127.0.0.1:9992/

Note, please do not directly use the rpc service provided by xwc_node, this service is currently only open to xwc_client internally.

Message structure

Jsonrpc's message is composed of request and response, one-to-one correspondence.

  • request

The Jsonrpc request includes the following structure:

{ 
“jsonrpc” : ”2.0”,
"method" : "info", 
"params" : [], 
"id" : 1
}

jsonrpc” - protocol version, currently fixed at "2.0"

method” – the name of the method to be called, please refer to the interface list below

params” – parameters required by the method, refer to the specific interface description

id” – the unique id of the request message. If the client needs to send multiple messages at the same time, this field will be returned intact by the server. The client can use this to identify which request corresponds to the message response.

  • response

The response includes the following structure:

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"head_block_num": 786742,
"head_block_id": "000c013669c0391fdd12eeacc8d2eafdd56fdd75",
"head_block_age": "5 seconds old",
"next_maintenance_time": "18 hours in the future",
"chain_id": "2e13ba07b457f2e284dcfcbd3d4a3e4d78a6ed89a61006cdb7fdad6d67ef0b12",
"participation": "100.00000000000000000",
"round_participation": "68.00000000000000000",
"scheduled_citizens": ["1.6.168","1.6.146","1.6.31","1.6.42","1.6.15","1.6.86","1.6.44","1.6.4","1.6.27","1.6.160","1.6.65","1.6.84",
"1.6.118","1.6.39","1.6.77","1.6.73","1.6.119","1.6.131","1.6.147","1.6.16","1.6.2","1.6.106","1.6.53","1.6.145",
"1.6.154"]
}
}

id” – the unique id of the request message, if the client needs to send multiple messages at the same time, this field will be returned intact by the server, and the client can use this to identify which request corresponds to the message response

jsonrpc” - protocol version, currently fixed at "2.0"

result” – the result returned by the call method, please refer to the following interface list

error” – if there is an error in the calling method, there will be this field, normally return without this field

HTTP sample

  • request

The request structure is as follows:

POST / HTTP/1.1
Host: 127.0.0.1:9992
Cache-Control: no-cache
{
"id":1,
“jsonrpc":"2.0",
"method":"info",
"params":[]
}
  • response

Note that the HTTP header is omitted here.

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"head_block_num": 786742,
"head_block_id": "000c013669c0391fdd12eeacc8d2eafdd56fdd75",
"head_block_age": "5 seconds old",
"next_maintenance_time": "18 hours in the future",
"chain_id": "2e13ba07b457f2e284dcfcbd3d4a3e4d78a6ed89a61006cdb7fdad6d67ef0b12",
"participation": "100.00000000000000000",
"round_participation": "68.00000000000000000",
"scheduled_citizens": [
"1.6.168",
"1.6.146",
"1.6.31",
"1.6.42",
"1.6.15",
"1.6.86",
"1.6.44",
"1.6.4",
"1.6.27",
"1.6.160",
"1.6.65",
"1.6.84",
"1.6.118",
"1.6.39",
"1.6.77",
"1.6.73",
"1.6.119",
"1.6.131",
"1.6.147",
"1.6.16",
"1.6.2",
"1.6.106",
"1.6.53",
"1.6.145",
"1.6.154"
]
}
}

curl example

  • request

The request command is as follows:

curl -X POST   http://127.0.0.1:9992/   -H 'cache-control: no-cache'   -H 'postman-token: a79b33f6-31a3-ec23-d114-d468f3d71c7c'   -d '{
  "jsonrpc": "2.0",
  "id": 61,
  "method": "info",
  "params": []
}'
  • response

The response is as follows:

{"id":61,
"jsonrpc":"2.0",
"result":
{"head_block_num":787040,
"head_block_id":"000c0260fb7dc04a7a6a1781ec54753cc9d536f4",
"head_block_age":"3 seconds old",
"next_maintenance_time":"18 hours in the future",
"chain_id":"2e13ba07b457f2e284dcfcbd3d4a3e4d78a6ed89a61006cdb7fdad6d67ef0b12",
"participation":"100.00000000000000000",
"round_participation":"64.00000000000000000",
"scheduled_citizens":["1.6.42","1.6.39","1.6.143","1.6.150","1.6.156","1.6.30","1.6.65","1.6.125","1.6.131","1.6.34","1.6.33","1.6.4","1.6.47","1.6.94","1.6.165","1.6.109","1.6.107","1.6.12","1.6.104","1.6.115","1.6.86","1.6.36","1.6.161","1.6.106","1.6.53"]}}

# Basic operating instructions

Get client information

Request

{"method":"info","id":20180523092052345,"jsonrpc":"2.0","params":[]}

successful response

{
	"id": "20180523092052345",
	"result": {
	"head_block_num": 634505,
	"head_block_id": "0009ae8941db944c1d2ec63cf64be2bd6b79b695",
	"head_block_age": "1 second old",
	"next_maintenance_time": "21 hours in the future",
	"chain_id": "2e13ba07b457f2e284dcfcbd3d4a3e4d78a6ed89a61006cdb7fdad6d67ef0b12",
	"participation": "98.43750000000000000",
	"round_participation": "24.00000000000000000",
	"scheduled_citizens": ["1.6.63", "1.6.33", "1.6.66", "1.6.95", "1.6.86", "1.6.112", "1.6.42", "1.6.54", "1.6.8", "1.6.52", "1.6.97", "1.6.123", "1.6.38", "1.6.139", "1.6.124", "1.6.31", "1.6.146", "1.6.115", "1.6.93", "1.6.4", "1.6.137", "1.6.53", "1.6.84", "1.6.27", "1.6.109"]
}
}

Return parameter:

"head_block_num ": block number,

"head_block_age ": the duration of the current largest block generation,

"next_maintenance_time ": "Next maintenance time on the chain",

"head_block_id ": "Current Block ID",

" chain_id ": "链ID",

"participation ": current participation rate on the chain,

"round_participation": "Current round participation rate",

"scheduled_citizens ": the citizen of the current block

Query on-chain parameters (handling fee, etc.)

request

{"method":"get_global_properties","id":20180523092052345,"jsonrpc":"2.0","params":[]}

response

{
	"id": "2.0.0",
	"parameters": {
		"current_fees": {
			"parameters": [
				[0, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[1, {
					"fee": 50
				}],
				[2, {
					"fee": 0
				}],
				[3, {
					"fee": 100
				}],
				[4, {
					"fee": 0
				}],
				[5, {
					"basic_fee": 500000,
					"premium_fee": 20000,
					"price_per_kbyte": 10
				}],
				[6, {
					"fee": 100,
					"price_per_kbyte": 10
				}],
				[7, {
					"fee": 300000
				}],
				[8, {
					"membership_annual_fee": 20000,
					"membership_lifetime_fee": 100000
				}],
				[9, {
					"fee": 5000
				}],
				[10, {
					"fee": 5000
				}],
				[11, {
					"fee": 100
				}],
				[12, {
					"fee": 5000
				}],
				[13, {
					"symbol3": 5000000,
					"symbol4": 3000000,
					"long_symbol": 50000,
					"price_per_kbyte": 10
				}],
				[14, {
					"fee": 5000,
					"price_per_kbyte": 10
				}],
				[15, {
					"fee": 5000
				}],
				[16, {
					"fee": 5000
				}],
				[17, {
					"fee": 100,
					"price_per_kbyte": 10
				}],
				[18, {
					"fee": 100
				}],
				[19, {
					"fee": 10
				}],
				[20, {
					"fee": 1000
				}],
				[21, {
					"fee": 5000
				}],
				[22, {
					"fee": 10
				}],
				[23, {
					"fee": 10
				}],
				[24, {
					"fee": 100000000
				}],
				[25, {
					"fee": 100
				}],
				[26, {
					"fee": 0
				}],
				[27, {
					"fee": 0
				}],
				[28, {
					"fee": 100,
					"price_per_kbyte": 10
				}],
				[29, {
					"fee": 100,
					"price_per_kbyte": 10
				}],
				[30, {
					"fee": 10
				}],
				[31, {
					"fee": 10
				}],
				[32, {
					"fee": 10
				}],
				[33, {
					"fee": 200,
					"price_per_kbyte": 10
				}],
				[34, {
					"fee": 0
				}],
				[35, {
					"fee": 1000000000
				}],
				[36, {
					"fee": 100
				}],
				[37, {
					"fee": 10
				}],
				[38, {
					"fee": 35000
				}],
				[39, {
					"fee": 10
				}],
				[40, {
					"fee": 200
				}],
				[41, {
					"fee": 45000
				}],
				[42, {
					"fee": 10,
					"price_per_kbyte": 10
				}],
				[43, {
					"fee": 10
				}],
				[44, {}],
				[45, {
					"fee": 100,
					"price_per_kbyte": 10
				}],
				[46, {
					"fee": 100
				}],
				[47, {
					"fee": 100
				}],
				[48, {
					"fee": 50,
					"price_per_output": 50
				}],
				[49, {
					"fee": 50,
					"price_per_output": 50
				}],
				[50, {
					"fee": 50
				}],
				[51, {}],
				[52, {
					"fee": 100
				}],
				[53, {}],
				[54, {
					"fee": 10
				}],
				[55, {
					"fee": 100
				}],
				[56, {
					"fee": 100
				}],
				[57, {
					"fee": 100
				}],
				[58, {
					"fee": 100
				}],
				[59, {
					"fee": 100
				}],
				[60, {
					"fee": 100
				}],
				[61, {
					"fee": 100
				}],
				[62, {
					"fee": 100
				}],
				[63, {
					"fee": 100
				}],
				[64, {
					"fee": 100
				}],
				[65, {
					"fee": 100
				}],
				[66, {
					"fee": 100
				}],
				[67, {
					"fee": 100
				}],
				[68, {
					"fee": 100
				}],
				[69, {
					"fee": 100
				}],
				[70, {
					"fee": 100
				}],
				[71, {
					"fee": 100
				}],
				[72, {
					"fee": 100
				}],
				[73, {
					"fee": 100
				}],
				[74, {
					"fee": 100
				}],
				[75, {
					"fee": 100
				}],
				[76, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[77, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[78, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[79, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[80, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[81, {
					"fee": 100,
					"price_per_kbyte": 100
				}],
				[82, {
					"fee": 100
				}],
				[83, {
					"fee": 100
				}],
				[84, {
					"fee": 100
				}],
				[85, {
					"fee": 100
				}],
				[86, {
					"fee": 100
				}],
				[87, {
					"fee": 100
				}],
				[88, {
					"fee": 100
				}],
				[89, {
					"fee": 100
				}],
				[90, {
					"fee": 100
				}],
				[91, {
					"fee": 100
				}],
				[92, {
					"fee": 5000
				}],
				[93, {
					"fee": 100
				}],
				[94, {
					"fee": 100
				}],
				[95, {
					"fee": 100
				}],
				[96, {
					"fee": 100
				}],
				[97, {
					"fee": 100
				}],
				[98, {
					"fee": 100
				}],
				[99, {
					"fee": 100
				}],
				[100, {
					"fee": 100
				}],
				[101, {
					"fee": 100000000
				}],
				[102, {
					"fee": 100
				}],
				[103, {
					"fee": 100
				}],
				[104, {
					"fee": 100
				}],
				[105, {
					"fee": 100
				}],
				[106, {
					"fee": 100
				}],
				[107, {
					"fee": 100
				}],
				[108, {
					"fee": 100
				}],
				[109, {
					"fee": 100
				}],
				[110, {
					"fee": 100
				}],
				[111, {
					"fee": 100
				}],
				[112, {
					"fee": 100
				}]
			],
			"scale": 10000
		},
		"block_interval": 5,
		"maintenance_interval": 86400,
		"maintenance_skip_slots": 3,
		"committee_proposal_review_period": 1209600,
		"maximum_transaction_size": 2048,
		"maximum_block_size": 2048000000,
		"maximum_time_until_expiration": 86400,
		"maximum_proposal_lifetime": 2419200,
		"maximum_asset_whitelist_authorities": 10,
		"maximum_asset_feed_publishers": 10,
		"maximum_miner_count": 1001,
		"maximum_guard_count": 15,
		"minimum_guard_count": 7,
		"maximum_authority_membership": 10,
		"reserve_percent_of_fee": 2000,
		"network_percent_of_fee": 2000,
		"lifetime_referrer_percent_of_fee": 3000,
		"cashback_vesting_period_seconds": 31536000,
		"cashback_vesting_threshold": 10000,
		"count_non_member_votes": true,
		"allow_non_member_whitelists": false,
		"miner_pay_per_block": 1000,
		"worker_budget_per_day": 50000000,
		"max_predicate_opcode": 1,
		"fee_liquidation_threshold": 10000,
		"accounts_per_fee_scale": 1000,
		"account_fee_scale_bitshifts": 4,
		"max_authority_depth": 2,
		"min_pay_back_balance": 100,
		"min_pay_back_balance_other_asset": [],
		"extensions": []
	},
	"next_available_vote_id": 217,
	"active_committee_members": ["1.5.0", "1.5.1", "1.5.2", "1.5.3", "1.5.4", "1.5.5", "1.5.6", "1.5.7", "1.5.8", "1.5.9", "1.5.10", "1.5.11", "1.5.12", "1.5.13", "1.5.14"],
	"active_witnesses": ["1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.6.5", "1.6.6", "1.6.7", "1.6.8", "1.6.9", "1.6.10", "1.6.11", "1.6.12", "1.6.13", "1.6.14", "1.6.15", "1.6.16", "1.6.17", "1.6.18", "1.6.19", "1.6.20", "1.6.21", "1.6.22", "1.6.23", "1.6.24", "1.6.25", "1.6.26", "1.6.27", "1.6.28", "1.6.29", "1.6.30", "1.6.31", "1.6.32", "1.6.33", "1.6.34", "1.6.35", "1.6.36", "1.6.37", "1.6.38", "1.6.39", "1.6.40", "1.6.41", "1.6.42", "1.6.43", "1.6.44", "1.6.45", "1.6.46", "1.6.47", "1.6.48", "1.6.49", "1.6.50", "1.6.51", "1.6.52", "1.6.53", "1.6.54", "1.6.55", "1.6.56", "1.6.57", "1.6.58", "1.6.59", "1.6.60", "1.6.61", "1.6.62", "1.6.63", "1.6.64", "1.6.65", "1.6.66", "1.6.67", "1.6.68", "1.6.69", "1.6.70", "1.6.71", "1.6.72", "1.6.73", "1.6.74", "1.6.75", "1.6.76", "1.6.77", "1.6.78", "1.6.79", "1.6.80", "1.6.81", "1.6.82", "1.6.83", "1.6.84", "1.6.85", "1.6.86", "1.6.87", "1.6.88", "1.6.89", "1.6.90", "1.6.91", "1.6.92", "1.6.93", "1.6.94", "1.6.95", "1.6.96", "1.6.97", "1.6.98", "1.6.99", "1.6.100", "1.6.101", "1.6.102", "1.6.103", "1.6.104", "1.6.105", "1.6.106", "1.6.107", "1.6.108", "1.6.109", "1.6.110", "1.6.111", "1.6.112", "1.6.113", "1.6.114", "1.6.115", "1.6.116", "1.6.117", "1.6.118", "1.6.119", "1.6.120", "1.6.121", "1.6.122", "1.6.123", "1.6.124", "1.6.125", "1.6.126", "1.6.127", "1.6.128", "1.6.129", "1.6.130", "1.6.131", "1.6.132", "1.6.133", "1.6.134", "1.6.135", "1.6.136", "1.6.137", "1.6.138", "1.6.139", "1.6.140", "1.6.141", "1.6.142", "1.6.143", "1.6.144", "1.6.145", "1.6.146", "1.6.147", "1.6.148", "1.6.149", "1.6.150", "1.6.151", "1.6.152", "1.6.153", "1.6.154", "1.6.155", "1.6.156", "1.6.157", "1.6.158", "1.6.159", "1.6.160", "1.6.161", "1.6.162", "1.6.163", "1.6.164", "1.6.165", "1.6.166", "1.6.167", "1.6.168", "1.6.169", "1.6.170", "1.6.171", "1.6.172", "1.6.173", "1.6.174", "1.6.175", "1.6.176", "1.6.177", "1.6.178", "1.6.179", "1.6.180", "1.6.181", "1.6.182", "1.6.183", "1.6.184", "1.6.185", "1.6.186", "1.6.187", "1.6.188", "1.6.189", "1.6.190", "1.6.191", "1.6.192", "1.6.193", "1.6.194", "1.6.195", "1.6.196", "1.6.197", "1.6.198", "1.6.199"],
	"unorder_blocks_match": [
		[6307200, 2700000],
		[12614400, 2500000],
		[18921600, 2400000],
		[25228800, 2200000],
		[31536000, 2100000],
		[37843200, 1900000],
		[44150400, 1700000],
		[4294967295, 200000]
	]
}

Parameter explanation:

The handling fee under the "current_fees" object is calculated separately according to the type, of which the type 60 transfer transaction is more commonly used. The transfer note is charged according to the length, and 0.001XWC is charged for every 1KB.

Create a wallet

Calling premise: the wallet does not exist.

Note: After the wallet is successfully created, the wallet is closed by default.

Request method: set_password Request parameter: Create password (length is not less than 8 digits)

request

{"method":"set_password","id":20180517140651383,"jsonrpc":"2.0","params":["12345678"]}

response

{"id":"20180517140651383","result":null}

Unlock wallet

Prerequisites for calling:

Wallet request method:

unlock request parameter: password

request

{"method":"unlock","id":20180517142746758,"jsonrpc":"2.0","params":["12345678"]}

response

{"id":"20180517142746758","result":null}

create Account

Prerequisite for calling: Unlock wallet

Request method: wallet _create_account

Request parameter: User name to be created (beginning with lowercase English characters, only lowercase English characters, numbers or underscores)

request

{"method":"wallet _create_account","id":20180517144818773,"jsonrpc":"2.0","params":["test"]}

response

{"id":"20180517144818773","result":"XWCNgycDeX4xna8w6cchoudZanQ8ssT9mriXh"}

result: Create account address

Query account information

Request method: get_account

Request parameter: Account name

request

{"method":"get_account","id":20180517144818773,"jsonrpc":"2.0","params":["hyper-exchange"]}

response

{"id":"20180517144818773","result": {
	"id": "1.2.229",
	"membership_expiration_date": "1970-01-01T00:00:00",
	"registrar": "1.2.0",
	"referrer": "1.2.0",
	"lifetime_referrer": "1.2.0",
	"network_fee_percentage": 2000,
	"lifetime_referrer_fee_percentage": 3000,
	"referrer_rewards_percentage": 0,
	"name": "hyper-exchange",
	"addr": "XWCNRGtrNXR5RD9rUxFQGr6o8D6Q6zm2zGvGJ",
	"owner": {
		"weight_threshold": 1,
		"account_auths": [],
		"key_auths": [
			["XWC6L9qtB2hMFVAmc9NowwHYiwkTSeemqK1RbytTG7uSP96uZd35t", 1]
		],
		"address_auths": []
	},
	"active": {
		"weight_threshold": 1,
		"account_auths": [],
		"key_auths": [
			["XWC6L9qtB2hMFVAmc9NowwHYiwkTSeemqK1RbytTG7uSP96uZd35t", 1]
		],
		"address_auths": []
	},
	"options": {
		"memo_key": "XWC6L9qtB2hMFVAmc9NowwHYiwkTSeemqK1RbytTG7uSP96uZd35t",
		"voting_account": "1.2.5",
		"num_witness": 0,
		"num_committee": 0,
		"votes": [],
		"miner_pledge_pay_back": 10,
		"extensions": []
	},
	"statistics": "2.9.229",
	"whitelisting_accounts": [],
	"blacklisting_accounts": [],
	"whitelisted_accounts": [],
	"blacklisted_accounts": [],
	"owner_special_authority": [0, {}],
	"active_special_authority": [0, {}],
	"top_n_control_flags": 0,
	"online": "true"
} }

result: account details

4.7 Check the address of the account in the wallet

Request method: get_account_balances

Request parameter: account name

request

{"method":"get_account_balances","id":20180517150216550,"jsonrpc":"2.0","params":["test"]}

reponse

{"id":"20180517150216550", "result": [{
	"amount": 16452,
	"asset_id": "1.3.0"
}, {
	"amount": 0,
	"asset_id": "1.3.3"
}] }

In the returned result, amount is the balance without precision asset_id is the asset id

Check balance by address

Request method: get_addr_balances

Request parameter: xwc address

request

{"method":"get_addr_balances","id":20180517150216550,"jsonrpc":"2.0","params":[" XWCNQoBQ6xLLRY5NvhjFX2UbessNAbP4E1LXm"]}

response

{"id":"20180517150216550", "result": [{
	"amount": 16452,
	"asset_id": "1.3.0"
}, {
	"amount": 0,
	"asset_id": "1.3.3"
}] }

Account transfer

Prerequisites for calling: Unlocking the wallet, there is an account

Request method in the wallet: transfer_to_address

Request parameters: withdrawal account, address to transfer to account, transfer amount, transfer asset type (XWC), remark information, whether to broadcast

request

{"method":"transfer_to_address","id":20180517150833029,"jsonrpc":"2.0",
"params":["test","XWCNQoBQ6xLLRY5NvhjFX2UbessNAbP4E1LXm","23",XWC,”hello world”,true]
}

response

{
	"id": "20180517150833029",
	"result": {
	"ref_block_num": 47371,
	"ref_block_prefix": 1886805367,
	"expiration": "2018-12-25T07:05:20",
	"operations": [
		[0, {
			"fee": {
				"amount": 100,
				"asset_id": "1.3.0"
			},
			"from": "1.2.0",
			"to": "1.2.0",
			"from_addr": "XWCNQ3vUe95it1pXVqjuUhMBPMf9B5mSLjBzR",
			"to_addr": "XWCNRGtrNXR5RD9rUxFQGr6o8D6Q6zm2zGvGJ",
			"amount": {
				"amount": 40311,
				"asset_id": "1.3.0"
			},
			"memo": {
				"from": "XWC1111111111111111111111111111111114T1Anm",
				"to": "XWC1111111111111111111111111111111114T1Anm",
				"nonce": 0,
				"message": "0000000068656c6c6f"
			},
			"extensions": []
		}]
	],
	"extensions": [],
	"signatures": ["1f0a02c4cee5146a47ec3a9fedcbc30543bac531351d0c8acf66151c4da445f985167616005ef0c34dcade32ff3750ee3322516e71870ec870f56f9cc53b2415ff"],
	"block_num": 0,
	"trxid": "34f1bf431281f2f62abb54bb98a36dd954495ef0"
}
}

Return parameter:

trx_id: transaction number (important)

block_num: block number (the transaction will be officially written after packaging)

is_virtual: reserved field

operations: structure type name

Transaction record query

Prerequisite for calling: wallet open

Request method: get_transaction

Request parameter: transaction id

request

{"method":"get_transaction","id":20180517153307898,"jsonrpc":"2.0",
"params":[“94711706fd82c84f3961136ba44d5dc251b8abb1”]}

response

{
	"id": "20180517150833029",
    "result": {
	"ref_block_num": 47371,
	"ref_block_prefix": 1886805367,
	"expiration": "2018-12-25T07:05:20",
	"operations": [
		[0, {
			"fee": {
				"amount": 100,
				"asset_id": "1.3.0"
			},
			"from": "1.2.0",
			"to": "1.2.0",
			"from_addr": "XWCNQ3vUe95it1pXVqjuUhMBPMf9B5mSLjBzR",
			"to_addr": "XWCNRGtrNXR5RD9rUxFQGr6o8D6Q6zm2zGvGJ",
			"amount": {
				"amount": 40311,
				"asset_id": "1.3.0"
			},
			"memo": {
				"from": "XWC1111111111111111111111111111111114T1Anm",
				"to": "XWC1111111111111111111111111111111114T1Anm",
				"nonce": 0,
				"message": "hello"
			},
			"extensions": []
		}]
	],
	"extensions": [],
	"signatures": ["1f0a02c4cee5146a47ec3a9fedcbc30543bac531351d0c8acf66151c4da445f985167616005ef0c34dcade32ff3750ee3322516e71870ec870f56f9cc53b2415ff"],
	"block_num": 637196,
	"trxid": "34f1bf431281f2f62abb54bb98a36dd954495ef0"
}
}

Return parameter:

id: transaction number

block_num: block number (after confirmation on the chain, the block number will not be 0)

operations: transaction op information, where red numbers are op types

fee: fee information

If the transaction id is not confirmed, the command cannot find any information

# Light wallet rpc interface

Get refinfo information on the chain

Request method: lightwallet_get_refblock_info

Request parameter: none

request

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"lightwallet_get_refblock_info",
  "params":[]
}

response

{
"id": 1,
"result": "11398,47706285"
}

Return parameter:

The string returned in result is refinfo

Broadcast transaction

Request method: lightwallet_broadcast

Request parameter: transaction to be broadcast (formatted as a line of json string)

request

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"lightwallet_broadcast",
  "params":[{"ref_block_num":20295,"ref_block_prefix":1522980328,"expiration":"2018-12-26T06:04:55","operations":[[0,{"fee":{"amount":200,"asset_id":"1.3.0"},"from":"1.2.0","to":"1.2.0","from_addr":"XWCNRhTbDKiw2ut91BJEc5zy49HKWQnRw9as7","to_addr":"XWCNUFt3gViQn3iXLRL9eTMGsaJFhYQ6RT4gM","amount":{"amount":10000000,"asset_id":"1.3.3"},"extensions":[]}]],"extensions":[],"signatures":["20434f13d89a088a1f6c3d4978c961885ff193237dca6dbae0e48224afb318f57c28001dd9162984a4f970979ffaf9870359c3da722af6699336a8d53b27c0ae60"]}]
}

response

{
"id": 1,
"result": "94711706fd82c84f3961136ba44d5dc251b8abb1"
}

Return parameter:

The string returned in result is the transaction id

# HRC12 token interface

Contract calls common interface

For HRC12 tokens, all interface calls are done through smart contract interface calls, so there is a relatively uniform format. The calling interface of the smart contract is divided into three categories, which have three different formats:

  1. invoke_contract: This type of call needs to consume a certain amount of XWC as GAS, and the result will be recorded on the blockchain. Its format is:

    method - invoke_contract 
    Parameter1 – Account Name (can be a local account name)
    Parameter2 - Gas limit, It is usually sufficient to set 0.00001 for each gas spent. If the network is congested, the value can be increased and the package is given priority.
    Parameter3 – Total gas Fee, This value is an estimated value and will be charged according to the actual number of steps executed during packaging. If the actual value is less than this value, the actual one shall prevail. Otherwise, the transaction will fail. If the failed transaction is not on the chain, the fee will be refunded, otherwise the fee will not be refunded.
    Parameter4 – Contract Address.
    Parameter5 – Contract Method, Just fill in the API document of the actual contract.
    Parameter6 –  Contract API Parameter, Fill in the interface according to the actual API document of the contract (usually multiple strings separated by ",")
    
  2. invoke_contract_testing: This type of interface performs the same logic as the previous one, but it will not be broadcast to the blockchain, and will only return the GAS consumed in operation, but it will not actually be consumed. It is mainly used for testing before calling the formal interface to make an estimate of the GAS that needs to be consumed. Its format is:

    method - invoke_contract_testing
    Parameter1 – Account name (can be a local account name)
    Parameter2 – Contract Address
    Parameter3 - Contract Method, Just fill in the API document of the actual contract
    Parameter4 – Contract API Parameter, Fill in the interface according to the actual API document of the contract (usually multiple strings separated by ",")
    
  3. invoke_contract_offline: This type of interface is only calculated locally, usually for some query functions, and does not consume GAS. Its format is:

    method - invoke_contract_testing
    Parameter1 – Account name (can be a local account name)
    Parameter2 – Contract Address
    Parameter3 - Contract Method, Just fill in the API document of the actual contract
    Parameter4 - Contract API Parameter, Fill in the interface according to the actual API document of the contract (usually multiple strings separated by ",")
    

The invoke_contract_testing method can only be executed on non-offline type interfaces, and is used to estimate even gas consumption. In actual use, the gas value returned by the testing interface will be increased by a little to pass in the actual invoke_contract method.

[offline]Get HRC12 token symbol

Request method: tokenSymbol

Request parameters: none

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract_offline", 
  "params": ["test", "XWCCWMNwuFzr3JSiDvGjZasDCm6dn2mVvxXKU", "tokenSymbol", ""], 
  "id": 1
}

Parameter description:

method: According to the HRC12 specification, the interface is an offline interface, so the method is "invoke_contract_offline"

test: the name of the account executing the contract (which can be a local account), which should be modified according to the actual situation

XWCCWMNwuFzr3JSiDvGjZasDCm6dn2mVvxXKU: contract address, each smart contract has a unique address, please modify according to the actual situation

tokenSymbol: contract method for querying the symbols of HRC12 tokens

Other parameters: According to different smart contract interfaces, the parameters are different, please refer to the specific specifications. No additional parameters are required in the tokenSymbol method, but an empty string placeholder is required.

response

{
"id": 1,
"jsonrpc": "2.0",
"result": "BTM"
}

The BTM in the returned result is the symbol of HRC12 token.

[offline]Get token name

Request method: tokenName

Request parameters: none

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract_offline", 
  "params": ["a", "XWCCWMNwuFzr3JSiDvGjZasDCm6dn2mVvxXKU", "tokenName", ""], 
  "id": 1
}

response

{
"id": 1,
"jsonrpc": "2.0",
"result": "Bytom"
}

Return parameter:

The BTM in the returned result is the name of the HRC12 token.

[offline]Get total tokens

Request method: totalSupply

Request parameters: none

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract_offline", 
  "params": ["a", "XWCCWMNwuFzr3JSiDvGjZasDCm6dn2mVvxXKU", "totalSupply", ""], 
  "id": 1
}

response

{
"id": 1,
"jsonrpc": "2.0",
"result": "2100000000"
}

Return parameter:

2100000000 in the returned result is the total supply of HRC12 tokens.

[offline]Get token accuracy

Request method: precision

Request parameters: none

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract_offline", 
  "params": ["a", "XWCCWMNwuFzr3JSiDvGjZasDCm6dn2mVvxXKU", " precision", ""], 
  "id": 1
}

response

{
"id": 1,
"jsonrpc": "2.0",
"result": "100000000"
}

Return parameter:

100000000 in the returned result is the accuracy of HRC12 tokens, which means that the smallest unit of the token is one part of 100000000.

[offline]Get the balance of an account

Request method: balanceOf

Request parameters: the address to be queried

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract_offline", 
  "params": ["a", "XWCCYDj67eqDChkrg1pmkm17LmWZCkVZdCSQd", "balanceOf", "XWCNWgseVgYxqJrWq4v7QbXjDiT7FAGToTa2R"], 
  "id": 1
}

response

{
"id": 1,
"jsonrpc": "2.0",
"result": "99699999800000000"
}

Return parameter:

In the returned result, 99699999800000000 is the number of HRC12 tokens in the query address, which needs to be divided by the accuracy when displayed.

Transfer

Request method: transfer

Request parameters: transfer-in address, amount, remarks

The amount is without precision, you need to multiply the actual amount by the accuracy of the token. Remarks are optional.

request

{
  "jsonrpc": "2.0", 
  "method": "invoke_contract", 
  "params": ["a", 0.00001, 500000, "XWCCYDj67eqDChkrg1pmkm17LmWZCkVZdCSQd", "transfer", "XWCNbtEpjh3GuSCSTAUtaC9vJUoKWjmEY8nnD,10,test"], 
  "id": 1
}

response

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"ref_block_num": 47218,
"ref_block_prefix": 303117421,
"expiration": "2019-03-06T05:39:30",
"operations": [
[
79,
{
"fee": {
"amount": 5100,
"asset_id": "1.3.0"
},
"invoke_cost": 500000,
"gas_price": 1,
"caller_addr": "XWCNWgseVgYxqJrWq4v7QbXjDiT7FAGToTa2R",
"caller_pubkey": "0362e1605ebc5e85ae510a4f2c736a1a6f9b6ce2b4979ea62b6b872d169ac4ba56",
"contract_id": "XWCCYDj67eqDChkrg1pmkm17LmWZCkVZdCSQd",
"contract_api": "transfer",
"contract_arg": "XWCNbtEpjh3GuSCSTAUtaC9vJUoKWjmEY8nnD,10,test"
}
]
],
"extensions": [],
"signatures": ["1f5481cae439b77103daf1ade23de91d2274aab448f3065e985c5a4f6741c3fd8906ecc730043101bad1a376da69605671218703ed617e80791b0ab4eb7d1fee02"
],
"block_num": 0,
"trxid": "29e16b8e00e3f9fd0714a7f469a0250ef179f76c"
}
}

Return parameter:

The returned result is the transaction information on the chain.

# Precautions

  • The times in the return value are all standard Greenwich Mean Time
  • The amount in the return value is the amount with precision. It needs to be reduced by 100,000 times to be the real amount. For example, if you transfer 1 XWC, then the return value is marked as 100,000.

# Reference documents

HRC12 specification:https://github.com/HcashOrg/HyperExchange/wiki/XWC-Token-contract-protocol(HRC12)

# Attachment: Common commands in the terminal command line mode

1.Create a wallet

set_password 12345678

Parameters: Wallet password

This operation will generate a wallet file, the default is wallet.json, if the file already exists, then set_password will become a password change operation

2.Unlock the wallet

unlock 12345678

Parameter: Wallet password

3.Create an account

wallet_create_account testaccount

Parameter: Account name

4.Import the private key

import_key testaccount1 private key 

Parameter: Account name private key that does not exist locally

5.List all accounts under the wallet

list_my_accounts

6.List account addresses

get_account_addr testaccount

Parameter: Account name

7.Export the private key

dump_private_key  testaccount1

Parameter: Account name

8.Check balance

get_account_balances testaccount

Parameter: Account name

9.Query parameters on the chain

get_global_properties

Parameter: None