If your blockchain has just been deployed, there is only a genesis account in the blockchain system. You can check the genesis account through the http interface (Example for localhost and 36002):
You may use or as the endpoint.
HTTP GET https://{endpoint}/getGenesisAccount
or
curl get https://{endpoint}/getGenesisAccount
For reference, to determine where exactly is the endpoint, refer below.
The value of address in the returned result is the genesis account.
You can query any account through the getAccount interface.
HTTP GET https://{endpoint}/getGenesisAccount?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
or
curl get https://{endpoint}/getGenesisAccount?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
HTTP Interfaces
Generating Public and Private Key pairs - Test
HTTP GET /createKeyPair
CURL command
curl get https://{endpoint}/createKeyPair
Function
Note: This interface is only for testing purposes. Do not use this interface in a production environment (SDK or command line used in production environment), because after calling this interface, if the node server is evil, the account's private key will be leaked. This interface only generates a public-private key pair and does not write to the entire network blockchain.
Return value
{
"error_code" : 0,
"result" : {
"address" : "ztxSkMvC2RcvXLpDgXBJCSb4m9mPe8gpNDKAG", //The account address
"private_key" : "privbzMRMFKoT8xPSPLqXoJb3GxgoULcR2go9WVNPG2N9e9oX251AgAU", //The private key of the account
"private_key_aes" : "7594a97bc5e6432704cc5f58ff60727ee9bda10a6117915d025553afec7f81527cb857b882b7c775391fe1fe3f7f3ec198ea69ada138b19cbe169a1a3fa2dec8", //The data after the private key of the account is encrypted with AES
"public_key" : "b00101da11713eaad86ad8ededfc28e86b8cd619ca2d593a21d8b82da34320a7e63b09c279bc", //The public key of the account
"public_key_raw" : "01da11713eaad86ad8ededfc28e86b8cd619ca2d593a21d8b82da34320a7e63b", //The data of the public key excluding the prefix and suffix
"sign_type" : "ed25519" //The type of the account encryption
}
}
getAccount
HTTP GET /getAccount?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV&key=hello&code=xxx&issuer=xxx
CURL command
curl get https://{endpoint}/getGenesisAccount?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
Function
Return information about the specified account and all its assets and metadata.
Parameters
Parameter
Description
address
The account address, required
key
The value of the key specified in the metadata of the account. If not filled, the returned result contains all the metadata
code, issuer
The asset code, and asset issuer. These two variables are either filled in at the same time or not filled at the same time. If you do not fill in, the returned results contain all the assets. If filled in, only the code and issuer are displayed in the returned results.
Return value
The content returned is as follows:
{
"error_code" : 0,//Error code, 0 means success
"result" : {
"address" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV", //The address of the account
"balance" : 300000000000,//Gas balance, in UGas
"nonce" : 1, //The number of transactions that the account has currently executed. If nonce is 0, this field is not displayed.
"assets" : [//The asset list
{
"amount" : 1400,//The amount of the asset
"key" ://Keyword of this asset
{
"code" : "CNY",//The asset code
"issuer" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV" //The account address of the asset issuer
}
}, {
"amount" : 1000,
"key" :
{
"code" : "USD",
"issuer" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV"
}
}
],
"assets_hash" : "9696b03e4c3169380882e0217a986717adfc5877b495068152e6aa25370ecf4a",//The hash value generated by the asset list
"contract" : null,//Contract. **Empty** means that the current contract is not a contract
"metadatas" : [//Metadata list
{
"key" : "123",//Keyword of metadata
"value" : "123_value",//Metadata content
"version" : 1 // Metadata version
}, {
"key" : "456",
"value" : "456_value",
"version" : 1
}, {
"key" : "abcd",
"value" : "abcd_value",
"version" : 1
}
],
"metadatas_hash" : "82c8407cc7cd77897be3100c47ed9d43ec4097ee1c00e2c13447187e5b1ac66c",//The hash value generated by the metadata list
"priv" : {//The privilege of the account
"master_weight" : 1,//The weight for the account
"thresholds" : {
"tx_threshold" : 1//The weight required to initiate a transaction
}
}
}
}
If the account does not exist, the content returned is as follows:
{
"error_code" : 4,//Error code, 4 means the account does not exist
"result" : null
}
getAccountBase
HTTP GET /getAccountBase?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
CURL command
curl get https://{endpoint}//getAccountBase?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
Function
Return basic information about the specified account, excluding assets and metadata.
Parameter
Parameter
Description
address
The account address, required
Return value
The content returned is as follows:
{
"error_code" : 0,//Error code, 0 indicates success
"result" : {
"address" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV", //The address of the account
"assets_hash" : "9696b03e4c3169380882e0217a986717adfc5877b495068152e6aa25370ecf4a",//The hash value generated by the asset list
"balance" : 899671600,//Gas balance in UGas
"contract" : null,//Contract. **Empty** indicates the current account is not a contract account
"nonce" : 1, //The number of transactions that the account has currently executed. If nonce is 0, this field is not displayed.
"priv" : {//Account privileges
"master_weight" : 1,//The weight of the account
"thresholds" : {
"tx_threshold" : 1 //The weight required to initiate a transaction
}
},
"metadatas_hash" : "82c8407cc7cd77897be3100c47ed9d43ec4097ee1c00e2c13447187e5b1ac66c" // The hash value generated by the metadata list
}
}
If the account does not exist, the content returned is as follows:
{
"error_code" : 4,//Error code, 4 indicates the account does not exist
"result" : null
}
getAccountAssets
HTTP GET /getAccountAssets?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
CURL command
curl get https://{endpoint}/getAccountAssets?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
Function
Return the asset information of the specified account.
Parameters
Parameter
Description
address
The account address, required
code, issuer
The issuer represents the asset issuance account address, and code represents the asset code. Only the correct code&issuer can be filled in at the same time to display the specified asset correctly or all assets will be displayed by default
Return value
The content returned is as follows:
{
"error_code" : 0,//Error code, 0 indicates the account does not exist
"result": [//If the result is not null, it indicates the asset is existed
{
"amount" : 1400,//The amount of assets owned
"key" ://Asset identification, including asset code and issuer
{
"code" : "EES",//Asset code
"issuer" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV" //The account address of the issuer
}
},
{
"amount" : 1000,
"key" :
{
"code" : "OES",
"issuer" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV"
}
}
]
}
If the account does not have an asset, the content returned is as follows:
{
"error_code" : 0,//Error code, 0 indicates the account does not existed
"result" : null //Result is null, indicating that the asset does not exist
}
getAccountMetaData
HTTP GET /getAccountMetaData?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
CURL command
curl get https://{endpoint}/getAccountMetaData?address=ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV
Function
Return the metadata information of the specified account.
Parameters
Parameter
Description
address
The account address, required
key
Optional. Specify the key value in the metadata
Return value
The content returned is as follows:
{
"error_code" : 0,//Error code, 0 indicates the account does not exist
"result": {//Result is not null, indicating that metadata exists
"123": {
"key" : "123",
"value" : "123_value",
"version" : 1
},
"456": {
"key" : "456",
"value" : "456_value",
"version" : 1
},
"abcd": {
"key" : "abcd",
"value" : "abcd_value",
"version" : 1
}
}
}
If the account does not have metadata, return the content:
{
"error_code" : 0,//Error code, 0 indicates the account does not exist
"result" : null //Result is null, indicating that the metadata does not exist
}
getTransactionHistory
HTTP GET /getTransactionHistory?ledger_seq=6
CURL command
curl get https://{endpoint}/getTransactionHistory?ledger_seq=6
Function
Return the completed transaction history.
Parameters
Parameter
Description
hash
Query with the hash, the unique identifier of the transaction
ledger_seq
Query all transactions in the specified block
Note: The constraint generated by the above two parameters is a logical AND. If you specify two parameters at the same time, the system will query the specified transaction in the specified block.
Return value
The content returned is as follows:
Note: There are two transactions below, and the 2nd transaction is a transaction to create a contract account. Please note the contents of the error_desc field.
{
"error_code": 0,//Error code, o indicates the transaction is exited
"result": {
"total_count": 2,//The number of transactions queried
"transactions": [{//The transaction list
"actual_fee": 313000,//The actual fee for the transaction
"close_time": 1524031260097214,//When the transaction is completed
"error_code": 0,// The error code of the transaction, 0 means the transaction is executed successfully, and non-zero means the transaction execution failed
"error_desc": "",//Description for the error in the transaction
"hash": "89a9d6e5d2c0e2b5c4fe58045ab2236d12e9449ef232342a48a2e2628e12014d",//The hash value of the transaction
"ledger_seq": 6,//The block height of the transaction
"signatures": [{//The signature list
"public_key": "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",//Public key
"sign_data": "27866d70a58fc527b1ff1b4a693b8034b0078fc7ac7591fb05679abe5ca660db5c372922bfa8f26e76511e2c33386306ded7593874a6aec5baeeaddbd2012f06"//Data signed
}],
"transaction": {//Transaction content
"fee_limit": 10000000000,//The maximum fee provided for this transaction, in UGas
"gas_price": 1000,//The price of gas, in UGas
"nonce": 1,//The sequence number of the transaction in the account
"operations": [{//The operation list
"create_account": {//The operation to create an account
"dest_address": "ztxSrDYeqnCeyDFNJQDdMJok3PB1jAhmctaWY",//The address of the target account
"init_balance": 10000000,//The initial Gas of the target account, in UGas
"priv": {//The privilege of the target account
"master_weight": 1,//The weight of the target account
"thresholds": {
"tx_threshold": 1 //The weight required to initiate a transaction for the target account
}
}
},
"type": 1 //The type of the operation, 1 means the operation is to create an account
},
{
"create_account": {
"dest_address": "ztxSVVQUx2GJSb1sfoWDMmHNpms4fuuA5s2WW",
"init_balance": 10000000,
"priv": {
"master_weight": 1,
"thresholds": {
"tx_threshold": 1
}
}
},
"type": 1
}],
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV" //The account address to initiate the transaction
},
"tx_size": 313 //The transaction byte
},
{
"actual_fee": 1000402000,//The actual fee for the transaction
"close_time": 1524031260097214,//When the transaction is completed
"error_code": 0,// The error code of the transaction, 0 means the transaction is executed successfully, and non-zero means the transaction execution failed
"error_desc": "[{\"contract_address\":\"ztxSpuMcbgPuNALPdRMJEQZhrMfA5u9ycUZCo\",\"operation_index\":0}]", //The result of contract creation, including contract address and operation index values
"hash": "4cbf50e03645f1075d7e5c450ced93e26e3153cf7b88ea8003b2fda39e618e64",//The hash value of the transaction
"ledger_seq": 6,//The block height of the transaction
"signatures": [{//The signature list
"public_key": "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",//Public key
"sign_data": "87fdcad0d706479e1a3f75fac2238763cd15fd93f81f1b8889fb798cefbe1752c192bbd3b5da6ebdb31ae47d8b62bb1166dcceca8d96020708f3ac5434838604" //Data signed
}],
"transaction": {//Transaction content
"fee_limit": 20004420000,//The maximum fee for this transaction
"gas_price": 1000,//The price of gas
"nonce": 30,//The sequence number of the transaction in the account
"operations": [{//The operation list
"create_account": {//The operation to create an account
"contract": {//Contract
"payload": "'use strict';\n\t\t\t\t\tfunction init(bar)\n\t\t\t\t\t{\n\t\t\t\t\t return;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfunction main(input)\n\t\t\t\t\t{\n\t\t\t\t\t return;\n\t\t\t\t\t}\n\t\t function query()\n\t\t\t\t\t{\n\t\t\t\t\t return;\n\t\t\t\t\t}\n\t\t \n\t\t " //Contract code
},
"init_balance": 10000000,//The initial Gas of the contract account, in UGas
"priv": {//The privilege of the contract account
"thresholds": {
"tx_threshold": 1 //The weight required to initiate a contract account transaction
}
}
},
"type": 1 // The operation type, 1 indicates the operation to create an account
}],
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV" //The account address to initiate the transaction
},
"tx_size": 402 //The transaction byte
}]
}
}
If no transaction is found, return the following content:
{
"error_code": 4,//Error code, 4 indicates no transaction
"result":
{
"total_count": 0,//The number of transactions queried
"transactions": []
}
}
getTransactionCache
HTTP GET /getTransactionCache?hash=ad545bfc26c440e324076fbbe1d8affbd8a2277858dc35927d425d0fe644e698&limit=100
CURL command
curl get https://{endpoint}/getTransactionCache?hash=ad545bfc26c440e324076fbbe1d8affbd8a2277858dc35927d425d0fe644e698&limit=100
Function
Return a transaction that is submitted successfully but not yet executed.
Parameters
Parameter
Description
hash
Query with the hash, the unique identifier of the transaction
limit
Query N transactions being processed in the transaction queue
Note: The constraint generated by the above two parameters is a logical OR. If you specify two parameters at the same time, the system will hash the query.
Return value
The content returned is as follows:
{
"error_code": 0,//Error code, 0 indicates the query is successful
"result": {
"total_count": 1,//The total transactions
"transactions": [//The transaction list
{
"hash": "a336c8f4b49c8b2c5a6c68543368ed3b450b6138a9f878892cf982ffb6fe234e",//The transaction hash
"incoming_time": 1521013029435154,//When the transaction enters the cache queue
"signatures": [//The signature list
{
"public_key": "b001882b9d1b5e7019f163d001c85194cface61e294483710f5e66ef40a4d387f5fcb0166f4f",//Public key
"sign_data": "c5885144ffccb0b434b494271258e846c30a4551036e483822ee2b57400576e9e700e8960eb424764d033a2e73af6e6a2bfa5da390f71161732e13beee206107" //Data signed
}
],
"status": "processing",//The transaction status
"transaction": {//Transaction content
"fee_limit": 100000,//The maximum fee provided for this transaction, in UGas
"gas_price": 1000,//The price of gas, in UGas
"nonce": 2,//The sequence number of the transaction in the account
"operations": [//The operation list
{
"create_account": {//The operation to create an account
"dest_address": "ztxSnVDvg3gfW8as4BeodEJDDQAMXu9NobyvN",//The address of the target account
"init_balance": 300000,//The initial Gas of the target account, in UGas
"priv": {//The privilege of the target account
"master_weight": 1,//The weight of the target account
"thresholds": {
"tx_threshold": 2 //The weight required to initiate a transaction for the target account
}
}
},
"type": 1 // The operation type, 1 indicates the operation to create an account
}
],
"source_address": "ztxSkScnQJ1ciM1C9rBVw6DbtogbAcWFuXRhC"// The account address to initiate the transaction
}
}
]
}
}
If no transaction is found, return the following content:
{
"error_code": 4,//Error code, 4 indicates no transaction is queried
"result":
{
"total_count": 0,//The number of transactions queried
"transactions": []
}
}
getLedger
HTTP GET /getLedger?seq=xxxx&with_validator=true&with_consvalue=true&with_fee=true
CURL command
curl get https://{endpoint}/getLedger?seq=6&with_validator=true&with_consvalue=true&with_fee=true
Function
Return information about block header.
Parameters
Parameter
Description
seq
The serial number of the ledger. If not filled, return the current ledger
with_validator
By default is false and the list of verification nodes is not displayed
with_consvalue
The default is false, and no consensus value is displayed
with_fee
The default is false, and the cost configuration is not displayed
Return value
Return the content as follows:
{
"error_code" : 0,//Error code, 0 indicates success
"result" : {
"block_reward" : 800000000,//Block reward, in UGas
"consensus_value" : {//Consensus content
"close_time" : 1524031260097214,//When the consensus is finished
"ledger_seq" : 6,//The block height
"previous_ledger_hash" : "ef329c7ed761e3065ab08f9e7672fd5f4e3ddd77b0be35598979aff8c21ada9b",//The hash of the previous block
"previous_proof" : "0ac1010a2c080110022a26080310052220432dde2fd32a2a66da77647231821c87958f56c303bd08003633952d384eb0b61290010a4c623030316435363833363735303137666662633332366538666232303738653532316566383435373234363236353339356536383934633835323434656566643262666130386635393862661240deeb9b782410f0f86d897006cac8ad152e56e4f914e5d718706de84044ef98baef25512a337865772641d57090b5c77e9e2149dbd41910e8d6cd85c3387ea708",//The certificate of the previous block
"previous_proof_plain" : {//The content of the previous block certificate
"commits" : [
{
"pbft" : {
"commit" : {
"sequence" : 5,//The serial number of the block
"value_digest" : "432dde2fd32a2a66da77647231821c87958f56c303bd08003633952d384eb0b6",//Summary
"view_number" : 3 //The serial number of the view
},
"round_number" : 1,
"type" : 2 //Type
},
"signature" : {//The signature of the node
"public_key" : "b001d5683675017ffbc326e8fb2078e521ef8457246265395e6894c85244eefd2bfa08f598bf",//Public key
"sign_data" : "deeb9b782410f0f86d897006cac8ad152e56e4f914e5d718706de84044ef98baef25512a337865772641d57090b5c77e9e2149dbd41910e8d6cd85c3387ea708" //Data signed
}
}
]
},
"txset" : {//Transaction set
"txs" : [//The transaction list
{
"signatures" : [//The signature list
{
"public_key" : "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",//Public key
"sign_data" : "27866d70a58fc527b1ff1b4a693b8034b0078fc7ac7591fb05679abe5ca660db5c372922bfa8f26e76511e2c33386306ded7593874a6aec5baeeaddbd2012f06" //Data signed
}
],
"transaction" : {//Transaction content
"fee_limit" : 10000000000,//The maximum fee provided for this transaction, in UGas
"gas_price" : 1000,//The price of gas, in UGas
"nonce" : 1,//The sequence number of the transaction in the account
"operations" : [//The operation list
{
"create_account" : {//The operation to create an account
"dest_address" : "ztxSrDYeqnCeyDFNJQDdMJok3PB1jAhmctaWY",//The target account
"init_balance" : 10000000,//The initial Gas of the target account, in UGas
"priv" : {//The privilege of the target account
"master_weight" : 1,//The weight owned by the target account
"thresholds" : {
"tx_threshold" : 1 //The weight required to initiate a transaction for the target account
}
}
},
"type" : 1 //The operation type, 1 indicates the operation is to create an account
},
{
"create_account" : {
"dest_address" : "ztxSVVQUx2GJSb1sfoWDMmHNpms4fuuA5s2WW",
"init_balance" : 10000000,
"priv" : {
"master_weight" : 1,
"thresholds" : {
"tx_threshold" : 1
}
}
},
"type" : 1
}
],
"source_address" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV"
}
},
{
"signatures" : [
{
"public_key" : "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",
"sign_data" : "fb7d9d87f4c9140b6e19a199091c6871e2380ad8e8a8fcada9b42a2911057111dc796d731f3f887e600aa89cc8692300f980723298a93b91db711155670d3e0d"
}
],
"transaction" : {
"fee_limit" : 10000000000,
"gas_price" : 1000,
"nonce" : 2,
"operations" : [
{
"create_account" : {
"dest_address" : "ztxSrbWSdMvysHtKQqpJzKAduQmDFHa1VHhRN",
"init_balance" : 10000000,
"priv" : {
"master_weight" : 1,
"thresholds" : {
"tx_threshold" : 1
}
}
},
"type" : 1
},
{
"create_account" : {
"dest_address" : "ztxSWwQmECKbyTTyx8RGVbaTapPqpHSPeskJy",
"init_balance" : 10000000,
"priv" : {
"master_weight" : 1,
"thresholds" : {
"tx_threshold" : 1
}
}
},
"type" : 1
}
],
"source_address" : "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV"
}
}
]
}
},
"fees" : {//The fee standard of blocks
"base_reserve" : 10000000,//The minimum Gas in the account, in UGas
"gas_price" : 1000 //The price of gas, in UGas
},
"header" : {//The block header
"account_tree_hash" : "6aca37dfe83f213942b21d02618b989619cfd7c0e67a8a14b0f7599dd4010aad",//The hash value of the account tree
"close_time" : 1524031260097214,//When the block is generated
"consensus_value_hash" : "14a65d69f619395135da2ff98281d5707494801f12184a4318b9a76383e651a8",//The hash value of onsensus content
"fees_hash" : "916daa78d264b3e2d9cff8aac84c943a834f49a62b7354d4fa228dab65515313",//The hash value of the fee standard
"hash" : "2cf378b326ab0026625c8d036813aef89a0b383e75055b80cb7cc25a657a9c5d",//The hash value of the block
"previous_hash" : "ef329c7ed761e3065ab08f9e7672fd5f4e3ddd77b0be35598979aff8c21ada9b",//The hash value of the previous block
"seq" : 6,//The block height
"tx_count" : 2,//The total transactions
"validators_hash" : "d857aa40ecdb123415f893159321eb223e4dbc11863daef86f35565dd1633316",//The hash value of the validation node list
"version" : 1000 //The block version
},
"validators" : [//The validation node list
"ztxSVW6zpibJ3amyauqk6339jjAgaL5LU9yAt" //The address of the validation node
]
}
}
Return the following content if no ledger is queried:
{ "error_code" : 4, "result" : null } ```
multiQuery
HTTP POST /multiQuery
CURL Command
curl localhost:26002/multiQuery -X POST -d "{\"items\":[{\"url\":\"getAccount?address=ztxSgJCoz19wLJ4KbFjb3KDFs96xeW966iYgD\",\"method\":\"GET\",\"jsonData\":\"\"},{\"url\":\"hello\",\"method\":\"GET\",\"jsonData\":\"\"}]}"
Function
Returning multiple query results according to the query list.
The body is in json format
Here the body pass is the query list. For example:
{
"items":
[
{
"url":"https://{endpoint}/?address=ztxSgJCoz19wLJ4KbFjb3KDFs96xeW966iYgD", // Query Command
"method": "GET", // GET or POST query
"jsonData":"" // If post query, here is the content of body
},
{
"url":"hello", // Query Command
"method": "GET", // GET or POST query
"jsonData":"" // If post query, here is the content of body
}
]
}
{
"error_code": 0,//The serialized transaction error code
"error_desc": "",//Description for the error
"result": {
"hash": "7ea4b61b86c5e2248e1ec24a8c04568e6b17c7121fb86f648b42b73bd3bada5d",//The transaction hash
"transaction_blob": "0a2462755173396e70614371396d4e465a473138717538385a636d5859716436627170545533100118a08d0620e8073aad01080122a8010a24627551747336446654354b6176745639344a675a79373548397069776d62374b6f555767123a123866756e6374696f6e206d61696e28696e707574537472297b0a202f2ae8bf99e698afe59088e7baa6e585a5e58fa3e587bde695b02a2f207d1a041a020801223e0a0568656c6c6f1235e8bf99e698afe5889be5bbbae8b4a6e58fb7e79a84e8bf87e7a88be4b8ade8aebee7bdaee79a84e4b880e4b8aa6d65746164617461" //The hexadecimal representation after serializing the transaction
}
}
submitTransaction
HTTP POST /submitTransaction
CURL command
curl https://{endpoint}/submitTransaction -X POST -d "{\"items\":[{\"transaction_blob\":\"0a2e61303032643833343562383964633334613537353734656234393736333566663132356133373939666537376236100122b90108012ab4010a2e61303032663836366337663431356537313934613932363131386363353565346365393939656232396231363461123a123866756e6374696f6e206d61696e28696e707574537472297b0a202f2ae8bf99e698afe59088e7baa6e585a5e58fa3e587bde695b02a2f207d1a06080a1a020807223e0a0568656c6c6f1235e8bf99e698afe5889be5bbbae8b4a6e58fb7e79a84e8bf87e7a88be4b8ade8aebee7bdaee79a84e4b880e4b8aa6d65746164617461\",\"signatures\":[{\"sign_data\":\"2f6612eaefbdadbe792201bb5d1e178aff118dfa0a640edb2a8ee91933efb97c4fb7f97be75195e529609a4de9b890b743124970d6bd7072b7029cfe7683ba2d\",\"public_key\":\"b00204e1c7dddc36d3153adcaa451b0ab525d3def48a0a10fdb492dc3a7263cfb88e80ee974ca4da0e1f322aa84ff9d11340c764ea756ad148e979c121619e9fe52e9054\"},{\"sign_data\":\"90C1CD2CD371F581EB8GasCDA295C390D62C19FE7F080FB981584FB5F0BAB3E293B613C827CB1B2E063E5783FFD7425E1DEC0E70F17C1227FBA5997A72865A30A\",\"public_key\":\"b00168eceea7900ddcb8f694161755f98590ba7944de3bfe339610fe0cacc10a18372dcbf71b\"}]}]}"
Function
Send the serialized transaction and signature list to the blockchain.
The body is in json format
{
"items" : [{//The transaction package list
"transaction_blob" : "0a2e61303032643833343562383964633334613537353734656234393736333566663132356133373939666537376236100122b90108012ab4010a2e61303032663836366337663431356537313934613932363131386363353565346365393939656232396231363461123a123866756e6374696f6e206d61696e28696e707574537472297b0a202f2ae8bf99e698afe59088e7baa6e585a5e58fa3e587bde695b02a2f207d1a06080a1a020807223e0a0568656c6c6f1235e8bf99e698afe5889be5bbbae8b4a6e58fb7e79a84e8bf87e7a88be4b8ade8aebee7bdaee79a84e4b880e4b8aa6d65746164617461",//The hexadecimal representation after serializing the transaction
"signatures" : [{//The first signature
"sign_data" : "2f6612eaefbdadbe792201bb5d1e178aff118dfa0a640edb2a8ee91933efb97c4fb7f97be75195e529609a4de9b890b743124970d6bd7072b7029cfe7683ba2d",//Data signed
"public_key" : "b00204e1c7dddc36d3153adcaa451b0ab525d3def48a0a10fdb492dc3a7263cfb88e80ee974ca4da0e1f322aa84ff9d11340c764ea756ad148e979c121619e9fe52e9054"//Public key
}, {//The second signature
"sign_data" : "90C1CD2CD371F581EB8GasCDA295C390D62C19FE7F080FB981584FB5F0BAB3E293B613C827CB1B2E063E5783FFD7425E1DEC0E70F17C1227FBA5997A72865A30A",//Data signed
"public_key" : "b00168eceea7900ddcb8f694161755f98590ba7944de3bfe339610fe0cacc10a18372dcbf71b"//Public key
}
]
}
]
}
Keywords in json
Parameter
Type
Description
transaction_blob
string
The hexadecimal format after the transaction is serialized
sign_data
string
Data signed, in hexadecimal format. Its value is the signature data obtained by signing (transaction) the transaction_blob. Note: when signing, you must first convert transaction_blob into byte stream and then sign, and do not directly sign hexadecimal string
public_key
string
The public key, in hexadecimal format
Return value
Note: The transaction is submitted and executed successfully.
{
"error_code": 0,//The result of the submission
"error_desc": "",//Description for the error
"result": {
"hash": "8e97ab885685d68b8fa8c7682f77ce17a85f1b4f6c8438eda8ec955890919405",//The transaction hash
}
}
In the design of the smart contract module, we provide a sandbox environment for debugging contracts, and the state of the blockchain and contract is not changed during debugging. On Zetrix, we provide you with the callContract interface to help you debug the smart contract. The smart contract can be stored in the public chain, or it can be tested by uploading the local contract code by parameters. The callContract interface will not be sent. Therefore, there is no need to pay for the transaction fee.
The body is in json format
{
"contract_address" : "",//Optional, the smart contract address
"code" : "\"use strict\";log(undefined);function query() { return 1; }",//Optional, the smart contract code
"input" : "{}",//Optional, pass parameters to the contract to be called
"contract_balance" : "100009000000",//The initial Gas balance assigned to the contract
"fee_limit" : 100000000000000000,//The transaction fee
"gas_price": 1000,//Optional, the gas price
"opt_type" : 2,//Optional, the operation type
"source_address" : "" //Optional, the original address of the simulated contract call
}
Keywords in json
Keyword
Type
Description
contract_address
string
The smart contract address that is called, or an error is returned if it is not quired from the database. If you left it blank, the content of the code field is read by default.
code
string
The contract code to be debugged, if the contract_address is empty, the code field is used, and if the code field is also empty, an error is returned
input
string
Pass the parameters to the contract to be called
contract_balance
string
The initial Gas balance assigned to the contract
fee_limit
int64
The transaction fee
gas_price
int64
The price of gas
opt_type
int
0: call the contract's read-write interface init, 1: call the contract's read-write interface main, 2: call the read-only interface query
source_address
string
Simulate the original address of the contract called
Return value
{
"error_code" : 0,//The result of the call, 0 means success
"error_desc" : "",//Description of error code
"result" : {
"logs" : {
"0-ztxSWaq8TmFVyyHKXsYwb9FTaGEx77EWW2hne" : null //Not used any more
},
"query_rets" : [
{
"result" : {
"type" : "bool", // Return the name of the variable
"value" : false // The value of the variable is false
}
}
],
"stat" : {
"apply_time" : 6315,//Execution time
"memory_usage" : 886176,//Memory usage
"stack_usage": 2564,//Stack usage
"step" : 3 //Frequency of execution
},
"txs" : null //Transaction set
}
}
The evaluation fee does not change the evaluation based on the account balance. The original account and the target account involved in the transaction must exist in the system, but the target address for creating the account does not have to be in the system.
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
//Fill in according to specific operations
},
{
//Fill in according to specific operations
}
......
]
}
Keywords in json
Keyword
Type
Description
source_address
string
The source account of the transaction, which is the account of the transaction initiator. When the transaction is successful, the nonce field of the source account will be automatically incremented by 1. The nonce in the account number is the number of transactions executed by this account
nonce
int64
Its value must be equal to the current nonce+1 of the source account of the transaction, which is designed to prevent replay attacks. If you want to know how to query the nonce of an account, you can refer to getAccount. If the account queried does not display the nonce value, the current nonce of the account is 0.
fee_limit
int64
The maximum fee that can be accepted for this transaction. The transaction will first charge a fee based on this fee. If the transaction is executed successfully, the actual cost will be charged, otherwise the fee for this field will be charged. The unit is UGas, 1 Gas = 10^6 UGas
gas_price
int64
It is used to calculate the handling fee for each operation and also involved in the calculation of the transaction byte fee. The unit is UGas, 1 Gas = 10^6 UGas
ceil_ledger_seq
int64
Optional, the block height restriction for this transaction, which is also an advanced feature
operations
array
The operation list. The payload of this transaction, which is what the transaction wants to do. See Operations Structure for more details
metadata
string
Optional, a user-defined field that can be left blank or filled in a note
Operations Structure
The corresponding operations in the json structure of the transaction can contain one or more operations.
In json format
{
"type": 1,//The operation type
"source_address": "adxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"create_account": {
//The parameters of the account to be created
},
"issue_asset": {
//The parameters of the asset to be issued
},
"pay_asset": {
//The parameters of the asset to be transferred
},
"set_metadata": {
//Set the relevant parameters of the account metadata
},
"pay_coin": {
//The parameters of the native token(Gas) to be transferred
},
"set_privilege": {
///The parameters of setting the account privileges
},
"log": {
//The parameters of the log
}
}
Keywords in json
Keyword
Type
Description
type
int
Operation code, different operation codes perform different operations, see Operation Codes for details
source_address
string
Optional, the source account of the operation, that is, the operator of the operation. When not filled in, the default is the same as the source account of the transaction
metadata
string
Optional, a user-defined field that can be left blank or filled in a note
create_account
json
The Creating Accounts operation
issue_asset
json
The Issuing Assets operation
pay_asset
json
The Transferring Assets operation
set_metadata
json
The Setting Metadata operation
pay_coin
json
The Transferring Gas Assets operation
log
json
The Recording Logs operation
set_privilege
json
The Setting Privileges operation
Operation Codes
Operation Code
Operation
Description
1
create_account
Creating Accounts
2
issue_asset
Issuing Assets
3
pay_asset
Transferring Assets
4
set_metadata
Setting Metadata
7
pay_coin
Transferring Gas Assets
8
log
Recording Logs
9
set_privilege
Setting Privileges
Creating Accounts
The source account creates a new account on the blockchain. Creating Accounts are divided into Creating Normal Accounts and Creating Contract Accounts.
Creating Normal Accounts
Note: Both master_weight and tx_threshold must be 1 in the current operation.
In json format
{
"dest_address": "ztxSfW5K2GkmzNgBG95qjyX2tgZezmUCHYMfp",//The target account address to be created
"init_balance": 100000,//The initial balance of the target account
"priv": {
"master_weight": 1,//The weight owned by the target account
"thresholds": {
"tx_threshold": 1//The threshold required to initiate a transaction
}
}
}
Keywords in json
Keyword
Type
Description
dest_address
string
The address of the target account. When creating a normal account, it cannot be empty
init_balance
int64
The initial Gas value of the target account, in UGas, 1 Gas = 10^6 UGas
master_weight
int64
The master weight of the target account, which ranges [0, MAX(UINT32)]
tx_threshold
int64
The threshold for initiating a transaction below which the transaction cannot be initiated, which ranges [0, MAX(INT64)]
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 1,//The create_account operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"create_account": {
"dest_address": "ztxSfW5K2GkmzNgBG95qjyX2tgZezmUCHYMfp",//The target account address to be created
"init_balance": 100000,//The initial balance of the target account
"priv": {
"master_weight": 1,//The weight owned by the target account
"thresholds": {
"tx_threshold": 1//The threshold required to initiate a transaction
}
}
}
}
]
}
Query
The account information is queried through the getAccount interface.
Creating Contract Accounts
Note: In the current operation, master_weight must be 0 and tx_threshold must be 1.
In json format
{
"contract": { //Contract
"payload": "
'use strict';
function init(bar)
{
return;
}
function main(input)
{
return;
}
function query()
{
return;
}
"//Contract code
},
"init_balance": 100000,//The initial asset of the contract account
"init_input" : "{\"method\":\"toWen\",\"params\":{\"feeType\":0}}",//Optional, the entry of the init function
"priv": {
"master_weight": 0,//The weight of the contract account to be created
"thresholds": {
"tx_threshold": 1 //The weight required to initiate a transaction
}
}
}
Keywords in json
Keyword
Type
Description
payload
string
The contract code
init_balance
int64
The initial Gas value of the target account, in UGas, 1 Gas = 10^6 UGas
init_input
string
Optional, the input parameter of the init function in the contract code
master_weight
int64
The master weight of the target account
tx_threshold
int64
The threshold for initiating a transaction below which it is not possible to initiate a transaction.
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 1,//The create_account operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"create_account": {
"contract": { //Contract
"payload": "
'use strict';
function init(bar)
{
return;
}
function main(input)
{
return;
}
function query()
{
return;
}
"//Contract code
},
"init_balance": 100000,//The initial asset of the contract account
"init_input" : "{\"method\":\"toWen\",\"params\":{\"feeType\":0}}",//Optional, the entry of the init function
"priv": {
"master_weight": 0,//The weight of the contract account to be created
"thresholds": {
"tx_threshold": 1 //The weight required to initiate a transaction
}
}
}
}
]
}
Query
The account information is queried through the getAccount interface.
Query with the getTransactionHistory interface, and the result is as follows:
[
{
"contract_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV", //The contract account
"operation_index": 0 //The operation index value in the transaction array, 0 means the first transaction
}
]
Issuing Assets
Function
The source account of this operation issues a digital asset, and this asset appears in the asset balance of the source account after successful execution.
In json format
{
"code": "HYL", //The code of the asset to be issued
"amount": 1000 //The amount of the asset to be issued
}
Keywords in json
Keyword
Type
Description
code
string
The code of the asset to be issued, which ranges [1, 64]
amount
int64
The amount of the asset to be issued, which ranges (0, MAX(int64))
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 2,//The issue_asset operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"issue_asset": {
"code": "HYL", //The code of the asset to be issued
"amount": 1000 //The amount of the asset to be issued
}
}
]
}
Transferring Assets
Note: If the target account is a contract account, the current operation triggers the contract execution of the target account.
Function
The source account of this operation transfers an asset to the target account.
In json format
{
"dest_address": "ztxSmcbrEqbnNKWxfeWCb8kHR8zGBxdviJ7Pd",//The target account to receive the asset
"asset": {
"key": {
"issuer": "ztxShgsZCaSrAQY3fS4xnvSruA2a9yBeopUYy",//The account to issue the asset
"code": "HYL" // The code of the asset to be transferred
},
"amount": 100 //The amount of the asset to be transferred
},
"input": "{\"bar\":\"foo\"}" // Optional, the input parameters of the main code of the contract code in the target account
}
Keywords in json
Keyword
Type
Description
dest_address
string
The address of the target account
issuer
string
The address of the issuer
code
string
The asset code which ranges [1, 64]
amount
int64
The amount of the asset which ranges (0,MAX(int64))
input
string
Optionally, if the target account is a contract account, the input will be passed to the argument of the main function of the contract code. This setting is invalid if the target account is a normal account
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000,//The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100,//Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 3,//The pay_asset operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"pay_asset": {
"dest_address": "ztxSmcbrEqbnNKWxfeWCb8kHR8zGBxdviJ7Pd",//The target account to receive the asset
"asset": {
"key": {
"issuer": "ztxShgsZCaSrAQY3fS4xnvSruA2a9yBeopUYy",//The account to issue the asset
"code": "HYL" // The code of the asset to be transferred
},
"amount": 100 //The amount of the asset to be transferred
},
"input": "{\"bar\":\"foo\"}" // Optional, the input parameters of the main code of the contract code in the target account
}
}
]
}
Setting Metadata
Function
The source account of this operation modifies or adds metadata to the metadata table.
In json format
{
"key": "abc",//Metadata Keyword
"value": "hello abc!",//Metadata content
"version": 0 //Optional, the metadata version
}
Keywords in json
Keyword
Type
Description
key
string
The keyword of metadata, which ranges (0, 1024].
value
string
The content of metadata, which ranges [0, 256K].
version
int64
Optional, metadata version number. The default value is 0. 0: when the value is zero, it means no limit version; >0: when the value is greater than zero, it means the current value version must be this value; <0: when the value is less than zero, it means the value is illegal
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 4,//The set_metadata operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"set_metadata": {
"key": "abc",//Metadata Keyword
"value": "hello abc!",//Metadata content
"version": 0 //Optional, the metadata version
}
}
]
}
Setting Privileges
Function
Set the weights that the signer has and set the thresholds required for each operation. For details, see Assignment of Control Rights.
In json format
{
"master_weight": "10",//Optional, the current account's weight
"signers": //Optional, a list of signers that need to operate
[
{
"address": "ztxSWriszctU64GQAKdVjCCgW7bSsTb8repJk",//The signer's address
"weight": 8 //Optional, the signer's weight
}
],
"tx_threshold": "2",//Optional, the threshold required to initiate the transaction
"type_thresholds": //Optional, the thresholds required for different operations
[
{
"type": 1,//The type of account creation
"threshold": 8 //Optional, the threshold required for this operation
},
{
"type": 2,//The type of asset issuance
"threshold": 9 //Optional, the threshold required for this operation
}
]
}
Keywords in json
Keyword
Type
Description
master_weight
string
Optional, by default "", it indicates the master weight of the account. "" : do not set this value; "0": set the master weight to 0; ("0", "MAX(UINT32)"]: set the weight value to this value; Other: illegal
signers
array
Optional, a list of signers that need to operate. By default is an empty object. Empty objects are not set
address
string
The signer's address that needs to operate, which should be in accordance with the address verification rules
weight
int64
Optional, by default is 0. 0: delete the signer; (0, MAX (UINT32)]: set the weight to this value, others: illegal
tx_threshold
string
Optional, by default "", it means the minimum privilege for the account. "", do not set this value; "0": set tx_threshold weight to 0; ("0", "MAX(INT64)"]: set the weight value to this value; others: illegal.
type_thresholds
array
Optional, a list of thresholds required for different operations; by default is an empty object. Empty objects are not set
type
int
To indicate a certain operation type (0, 100]
threshold
int64
Optional, by default is 0. 0: delete the type operation; (0, MAX(INT64)]: set the weight value to this value; Other: illegal
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 9,//The set_privilege operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"set_privilege": {
"master_weight": "10",//Optional, the current account's weight
"signers"://Optional, a list of signers that need to operate
[
{
"address": "ztxSWriszctU64GQAKdVjCCgW7bSsTb8repJk",//The signer's address
"weight": 8 //Optional, the signer's weight
}
],
"tx_threshold": "2",//Optional, the threshold required to initiate the transaction
"type_thresholds"://Optional, the thresholds required for different operations
[
{
"type": 1,//The type of account creation
"threshold": 8 //Optional, the threshold required for this operation
},
{
"type": 2,//The type of asset issuance
"threshold": 9 //Optional, the threshold required for this operation
}
]
}
}
]
}
Transferring Gas Assets
Note: If the target account is a contract account, the current operation triggers the contract execution of the target account.
Function
Two functions:
The source account of this operation transfers a Gas asset to the target account.
The source account of this operation creates a new account on the blockchain.
In json format
{
"dest_address": "ztxSgGkHuPv6FQUu6C5uWnaqyKJ22bSNrJUCJ",//The target account to receive Gas assets
"amount": 100,//The amount of Gas assets to be transferred
"input": "{\"bar\":\"foo\"}" // Optional, the input parameters of the main code of the contract code in the target account
}
Keywords in json
Keyword
Type
Description
dest_address
string
The target account
amount
array
Optional, a list of signers that need to operate. By default is an empty object. Empty objects are not set.
input
string
Optionally, if the target account is a contract account, and the input will be passed to the argument of the main function of the contract code. This setting is invalid if the target account is a normal account.
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 7,//The pay_coin operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"pay_coin": {
"dest_address": "ztxSgGkHuPv6FQUu6C5uWnaqyKJ22bSNrJUCJ",//The target account to receive Gas assets
"amount": 100,//The amount of Gas assets to be transferred
"input": "{\"bar\":\"foo\"}" // Optional, the input parameters of the main code of the contract code in the target account
}
}
]
}
Recording Logs
Function
The source account of this operation writes the log to the blockchain.
In json format
{
"topic": "hello",// The topic of the log
"datas"://The content of the log
[
"hello, log 1",
"hello, log 2"
]
}
Keywords in json
Keyword
Type
Description
topic
string
The log topic and the parameter length is (0,128]
datas
array
The log content. The length of each element is (0,1024]
Complete transaction structure
{
"source_address":"ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//The source account, also called the originator of the transaction
"nonce":2, //The nonce value of the source account
"fee_limit" : 1000000, //The transaction fee that you intend to pay
"gas_price": 1000,//The gas price (not less than the minimum configured)
"ceil_ledger_seq": 100, //Optional, block height limit, if greater than 0, the transaction is only valid below (including the height) the block height
"metadata":"0123456789abcdef", //Optional, a user-defined note for transactions, in hexadecimal format
"operations":[
{
"type": 8,//The log operation type
"source_address": "ztxSn8xpL7c2xkxwbreVCs6EZ7KZbBvtDaLtV",//Optional, the source account of the operations
"metadata": "0123456789abcdef",//Optional, a user-defined note for transactions, in hexadecimal format
"log": {
"topic": "hello",// The topic of the log
"datas"://The content of the log
[
"hello, log 1",
"hello, log 2"
]
}
}
]
}
Assignment of Control Rights
When you create an account, you can specify the control assignment for this account. You can set this by setting the value of priv. Here is a simple example.
{
"master_weight": "70",//The weight for the private key of this address is 70
"signers": [//The weights assigned
{
"address": "ztxSigpdiWcW22hw54i9PEFk1s4WLEy5Rmh6K",
"weight": 55 //The weight of the above address is 55
},
{
"address": "ztxSX1SypC33doY4a5MYYr5zBZUvB33kKHdAo",
"weight": 100 //The weight of the above address is 100
}
],
"tx_threshold": "8",//The weight required to initiate the transaction is 8
"type_thresholds": [
{
"type": 1,//The weight required to create an account is 11
"threshold": 11
},
{//The weight required to issue an asset is 21
"type": 2,
"threshold": 21
},
{//The weight required to transfer assets is 31
"type": 3,
"threshold": 31
},
{//The weight required to set metadata is 41
"type": 4,
"threshold": 41
},
{//The weight required to change controllers is 51
"type": 5,
"threshold": 51
},
{//The weight required to change operations is 61
"type": 6,
"threshold": 61
}
]
}
Example
Next, we use ztxSW512jUyDASna878ECgZ4QFyhh6AtEJP6E to initiate a transaction. This transaction has only one operation, that is, creating a new account ztxSX1SypC33doY4a5MYYr5zBZUvB33kKHdAo, and completing the account creation process by transferring Gas to the new account.
Assembling Transactions
Referring to the structure of Transaction Structure, the following three steps are required:
Obtaining the account nonce value
Assembling operations
Generating transaction objects
Obtaining the Account Nonce Value
In the structure of the transaction, it is necessary to confirm the serial number of the transaction in the transaction initiation account. Therefore, it is necessary to obtain the nonce value of the transaction initiation account through the getAccountBase interface, and increase the nonce value by 1 based on its nonce value.
The interface call is as follows:
HTTP GET https://{endpoint}/getAccountBase?address=ztxSW512jUyDASna878ECgZ4QFyhh6AtEJP6E
or
curl get https://{endpoint}/getAccountBase?address=ztxSW512jUyDASna878ECgZ4QFyhh6AtEJP6E
According to the structure of Operations Structure, Operation Codes, and Transferring Gas Assets structure, the json format of the generation operation is as follows:
In Obtaining the Account Nonce Value, the nonce value is 20, then the serial number of the new transaction is 21. According to the operation structure obtained in the Assembling Operations, the json format of the transaction is generated as follows:
This is done through the getTransactionBlob interface.
The interface call is as follows:
HTTP POST https://{endpoint}/getTransactionBlob
or
curl https://{endpoint}/getTransactionBlob -X POST -d "{\"source_address\":\"ztxSW512jUyDASna878ECgZ4QFyhh6AtEJP6E\",\"nonce\":21,\"fee_limit\":1000000,\"gas_price\":1000,\"operations\":[{\"type\":7,\"pay_coin\":{\"dest_address\":\"ztxSX1SypC33doY4a5MYYr5zBZUvB33kKHdAo\",\"amount\":10000000,\"input\":\"\"}}]}"
Signing signatures is to sign the value of transaction_blob in getTransactionBlob with the private key of ztxSW512jUyDASna878ECgZ4QFyhh6AtEJP6E and generate a public key. For details, please refer to keypair. The resulting signature data is as follows:
According to the signature data obtained by Signing Signatures and the transaction_blob obtained by Serializing Transaction Data, the json format of the body in the submitTransaction interface is generated as follows:
HTTP POST https://{endpoint}/submitTransaction
or
curl https://{endpoint}/submitTransaction -X POST -d "{\"items\":[{\"transaction_blob\":\"0a246275516f50326552796d4163556d33757657675138526e6a7472536e58425866417a7356101518c0843d20e8073a2f0807522b0a24627551747336446654354b6176745639344a675a79373548397069776d62374b6f5557671080ade204\",\"signatures\":[{\"sign_data\":\"ACF64A7D41244AFC4465DBC225D616E0499776140D46BA7A84B1B6B263DAF1422904137E0181301F480F7114EC7CC5BBE4763EDA981E565EF81EF7705596CB0B\",\"public_key\":\"b00168eceea7900ddcb8f694161755f98590ba7944de3bfe339610fe0cacc10a18372dcbf71b\"}]}]}"
According to the hash obtained by the submitTransaction interface, confirm whether the transaction is executed successfully by the getTransactionHistory interface (check whether error_code under transactions is equal to 0).
The interface call is as follows:
HTTP GET https://{endpoint}/getTransactionHistory?hash=3f90865062d7737904ea929cbde7c45e831e4972cf582b69a0198781c452e9e1
or
curl get https://{endpoint}/getTransactionHistory?hash=3f90865062d7737904ea929cbde7c45e831e4972cf582b69a0198781c452e9e1