Skip to content

Java Bytom Doc

JackyKen edited this page Jul 24, 2018 · 1 revision

SDK documentation

This page will document the API classes and ways to properly use the API. Subsequent new releases also maintain backward compatibility with this class approach. Welcome please submit the issue in Github directly. Bytom-JAVA-SDK Issues

Basic Usage

   public static Client generateClient() throws BytomException {
		String coreURL = Configuration.getValue("bytom.api.url");
		String accessToken = Configuration.getValue("client.access.token");
		if (coreURL == null || coreURL.isEmpty()) {
			coreURL = "http://127.0.0.1:9888/";
		}
		return new Client(coreURL, accessToken);
	}
	
    Client client = generateClient();

API methods

available with wallet enable

available Whether or not the wallet is open


create-key

Parameters

Object:

  • String - alias, name of the key.
  • String - password, password of the key.
Returns

Object:

  • String - alias, name of the key.
  • String - xpub, pubkey of the key.
  • String - file, path to the file of key.
Example
// Request
Key key = Key.create(client, "testkey004", "123456");

// Result
{
  "alias": "alice",
  "xpub": "a7dae957c2d35b42efe7e6871cf5a75ebd2a0d0e51caffe767db42d3e6d69dbe211d1ca492ecf05908fe6fa625ad61b3253375ea744c9442dd5551613ba50aea",
  "file": "/Path/To/Library/Bytom/keystore/UTC--2018-04-22T06-30-27.609315219Z--0e34293c-8856-4f5f-b934-37456a3820fa"
}

list-keys

Parameters

none

Returns
  • Array of Object, keys owned by the client.
    • Object:
      • String - alias, name of the key.
      • String - xpub, pubkey of the key.
Example
// Request
Key.Items keys = new Key.QueryBuilder().list(client);

// Result
[
  {
    "alias": "alice",
    "xpub": "a7dae957c2d35b42efe7e6871cf5a75ebd2a0d0e51caffe767db42d3e6d69dbe211d1ca492ecf05908fe6fa625ad61b3253375ea744c9442dd5551613ba50aea",
    "file": "/Path/To/Library/Bytom/keystore/UTC--2018-04-21T02-35-15.035935116Z--4f2b8bd7-0576-4b82-8941-6cc6da05efe3"
  },
  {
    "alias": "bob",
    "xpub": "d30a810e88532f73816b7b5007d413cbd21e526ae9159023e5262511893adc1526b8eacd691b27c080201d7d79336a4f3d2cb4c167d997821cad445765916254",
    "file": "/Path/To/Library/Bytom/keystore/UTC--2018-04-22T06-30-27.609315219Z--0e34293c-8856-4f5f-b934-37456a3820fa"
  }
]

delete-key

Parameters

Object:

  • String - xpub, pubkey of the key.
  • String - password, password of the key.
Returns

Boolen - flag, success return true.

Example
// Request
Key key = Key.create(client, "testdelkey", "123456");

// Result
true

reset-key-password

Parameters

Object:

  • String - xpub, pubkey of the key.
  • String - old_password, old password of the key.
  • String - new_password, new password of the key.
Returns

Boolen - flag, success return true.

Example
// Request
Key.resetPassword(client, key.xpub, "123456", "111111");

// Result
true

create-account

Parameters

Object:

  • Array of String - root_xpubs, pubkey array.
  • String - alias, name of the account.
  • Integer - quorum, the default value is 1, threshold of keys that must sign a transaction to spend asset units controlled by the account.

Optional:

  • String - access_token, if optional when creating account locally. However, if you want to create account remotely, it's indispensable.
Returns

Object:

  • String - id, account id.
  • String - alias, name of account.
  • Integer - key_index, key index of account.
  • Integer - quorom, threshold of keys that must sign a transaction to spend asset units controlled by the account.
  • Array of Object - xpubs, pubkey array.
Example
// Request
Key key = Key.create(client, "keytest0033", "123456");
if (key != null && key.xpub != null) {
	Account account = new Account.Builder()
	                             .setAlias("hello_bytom9") 
				     .addXpub(key.xpub)
				     .setQuorum(1)
				     .create(client);
}

// Result
{
  "alias": "alice",
  "id": "08FO663C00A02",
  "key_index": 1,
  "quorum": 1,
  "xpubs": [
    "02581f1a2099e1696c498901c0049a22cc3e7f85db71c4ebb78f238d3ef8b323d2fd5c33b6f634aacdd25eb5e09c0c803077c521ef0524e4cc64d1a4420c8bc6"
  ]
}

list-accounts

Parameters

none

Returns
  • Array of Object, account array.
    • Object:
      • String - id, account id.
      • String - alias, name of account.
      • Integer - key_index, key index of account.
      • Integer - quorom, threshold of keys that must sign a transaction to spend asset units controlled by the account.
      • Array of Object - xpubs, pubkey array.
Example

list all the available accounts:

// Request
Account.Items items = new Account.QueryBuilder().list(client);

// Result
[
  {
    "alias": "alice",
    "id": "086KQD75G0A02",
    "key_index": 1,
    "quorum": 1,
    "xpubs": [
      "180aab8bf247932a7cf68da5cc9a873266279155097612f1e5fdda4add88d5e91e2e7ce5b736f3ac933824cdee9effcf1531b90dfcb388e5cc306d14e9a2c85e"
    ]
  },
  {
    "alias": "bob",
    "id": "086KQO67G0A04",
    "key_index": 2,
    "quorum": 1,
    "xpubs": [
      "180aab8bf247932a7cf68da5cc9a873266279155097612f1e5fdda4add88d5e91e2e7ce5b736f3ac933824cdee9effcf1531b90dfcb388e5cc306d14e9a2c85e"
    ]
  }
]

delete-account

Parameters

Object:

  • String - account_info, alias or ID of account.
Returns

Boolen - flag, success return true.

Example
// Request
new Account().delete(client, "hello_bytom9");

// Result
true

create-account-receiver

Parameters

Object: account_alias | account_id

optional:

  • String - account_alias, alias of account.
  • String - account_id, id of account.
Returns

Object:

  • String - address, address of account.
  • String - control_program, control program of account.
Example

//Request

new Account.ReceiverBuilder()
	   .setAccountId("0DSPTV6T00A08")
	   .create(client);

// Result

{
    "address": "bm1q5u8u4eldhjf3lvnkmyl78jj8a75neuryzlknk0",
    "control_program": "0014a70fcae7edbc931fb276d93fe3ca47efa93cf064"
}

list-addresses

Parameters
  • String - account_alias, alias of account.
  • String - account_id, id of account.
Returns
  • Array of Object, account address array.
    • Object:
      • String - account_alias, alias of account.
      • String - account_id, id of account.
      • String - address, address of account.
      • Boolean - change, whether the account address is change.
Example

list all the addresses:

// Request
Account.AddressBuilder.Items items = new Account.AddressBuilder()
                                                .setAccountId("0DSPTV6T00A08")
				                .list(client);

// Result
[
  {
    "account_alias": "alice",
    "account_id": "0DSPTV6T00A08",
    "address": "bm1qcn9lf7nxhswratvmg6d78nq7r7yupm36qgsv55",
    "change": false
  },
  {
    "account_alias": "bob",
    "account_id": "0DSPTV6T00A08",
    "address": "bm1qfkf3tyc95m0axv2mfnjsnu7l0h5tyfnpgpud4lsz5m0xkqmhgy9sd4x24h",
    "change": false
  }
]

list all the addresses by account_id or account_alias:

// Request
Account.AddressBuilder.Items items = new Account.AddressBuilder()
                                                .setAccountId("0DSPTV6T00A08")
						.list(client);

// Result
[
  {
    "account_alias": "alice",
    "account_id": "0DSPTV6T00A08",
    "address": "bm1qcn9lf7nxhswratvmg6d78nq7r7yupm36qgsv55",
    "change": false
  },
  {
    "account_alias": "alice",
    "account_id": "0DSPTV6T00A08",
    "address": "bm1qew4h5uvt5ssrtg2alms0j77r94c30m78ucrcxy",
    "change": false
  },
  {
    "account_alias": "alice",
    "account_id": "0DSPTV6T00A08",
    "address": "bm1qgnp4lte7wge0rsekevjlrdh39vkzz0c2alheue",
    "change": false
  }
]

validate-address

Parameters

Object:

  • string - address, address of account.
Returns

Object:

  • Boolean - valid, whether the account address is valid.
  • Boolean - is_local, whether the account address is local.
Example

check whether the address is vaild or not.

// Request
Address address = new Account.AddressBuilder()
                             .validate(client, "bm1qg3v9awlqh530fv7aqh230pkf62rpp35lap3unt");

// Result
{
   "valid": true,
   "is_local": true,
}

create-asset

Parameters

Object:

  • Array of String - root_xpubs, pubkey array.
  • String - alias, name of the asset.
  • Integer - quorum, the default value is 1, threshold of keys that must sign a transaction to spend asset units controlled by the account.

Optional:

  • Object - definition, definition of asset.
  • String - access_token, if optional when creating asset locally. However, if you want to create asset remotely, it's indispensable.
Returns

Object:

  • String - id, asset id.
  • String - alias, name of the asset.
  • String - issuance_program, control program of the issuance of asset.
  • Array of Object - keys, information of asset pubkey.
  • String - definition, definition of asset.
  • Integer - quorum, threshold of keys that must sign a transaction to spend asset units controlled by the account.
Example

create asset.

// Request
Asset testAsset = new Asset.Builder()
                           .setAlias(asset)
			   .addRootXpub(key.xpub)
			   .setQuorum(1)
			   .setDefinition(def)
			   .addDefinitionField("test", test)
			   .create(client);

// Result
{
  "id": "3c1cf4c9436e3f942cb2f1d70a584f1c61df3697698dacccdc89e46f46a003d0",
  "alias": "GOLD",
  "issuance_program": "766baa209683b893483c0a5a317bf9868a8e2a09691f8aa8c1f3e2a7bb62b157e76712e05151ad696c00c0",
  "keys": [
    {
      "root_xpub": "f6a16704f745a168642712060e6c5a69866147e21ec2447ae628f87d756bb68cc9b91405ad0a95f004090e864fde472f62ba97053ea109837bc89d63a64040d5",
      "asset_pubkey": "9683b893483c0a5a317bf9868a8e2a09691f8aa8c1f3e2a7bb62b157e76712e012bd443fa7d56a0627df0a29dffcdc52641672a0f5cba54d104ad76ebeb8dfc3",
      "asset_derivation_path": [
        "000200000000000000"
      ]
    }
  ],
  "quorum": 1,
  "definition": {}
}

get-asset

Parameters

Object:

  • String - id, id of asset.
Returns

Object:

  • String - id, asset id.
  • String - alias, name of the asset.
  • String - issuance_program, control program of the issuance of asset.
  • Integer - key_index, index of key for xpub.
  • Integer - quorum, threshold of keys that must sign a transaction to spend asset units controlled by the account.
  • Array of Object - xpubs, pubkey array.
  • String - type, type of asset.
  • Integer - vm_version, version of VM.
  • String - raw_definition_byte, byte of asset definition.
  • Object - definition, description of asset.
Example

get asset by assetID.

// Request
Asset queryAsset = new Asset.QueryBuilder()
                            .setAssetId(testAsset.id)
			    .get(client);

// Result
{
  "alias": "SILVER",
  "definition": null,
  "id": "50ec80b6bc48073f6aa8fa045131a71213c33f3681203b15ddc2e4b81f1f4730",
  "issue_program": "ae2029cd61d9ef31d40af7541f9a50831d6317fdb0870249d0564fcfa9a8f843589c5151ad",
  "key_index": 1,
  "quorum": 1,
  "raw_definition_byte": "",
  "type": "asset",
  "vm_version": 1,
  "xpubs": [
    "34b16ee500615cd325f8b84099f83c1ebecaca67977c5dc9b71ae32ceaf18207f996b0a9725b901d3792689b2babcb60febe3b81a684d9b56b65f67f307d453d"
  ]
}

list-assets

Parameters

none

Returns
  • Array of Object, asset array.
    • Object:
      • String - id, asset id.
      • String - alias, name of the asset.
      • String - issuance_program, control program of the issuance of asset.
      • Integer - key_index, index of key for xpub.
      • Integer - quorum, threshold of keys that must sign a transaction to spend asset units controlled by the account.
      • Array of Object - xpubs, pubkey array.
      • String - type, type of asset.
      • Integer - vm_version, version of VM.
      • String - raw_definition_byte, byte of asset definition.
      • Object - definition, description of asset.
Example

list all the available assets:

// Request
Asset.Items items = new Asset.QueryBuilder().list(client);

// Result
[
  {
    "alias": "BTM",
    "definition": {
      "decimals": 8,
      "description": "Bytom Official Issue",
      "name": "BTM",
      "symbol": "BTM"
    },
    "id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
    "issue_program": "",
    "key_index": 0,
    "quorum": 0,
    "raw_definition_byte": "7b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a20224279746f6d204f6666696369616c204973737565222c0a2020226e616d65223a202262746d222c0a20202273796d626f6c223a202262746d220a7d",
    "type": "internal",
    "vm_version": 1,
    "xpubs": null
  },
  {
    "alias": "SILVER",
    "definition": null,
    "id": "50ec80b6bc48073f6aa8fa045131a71213c33f3681203b15ddc2e4b81f1f4730",
    "issue_program": "ae2029cd61d9ef31d40af7541f9a50831d6317fdb0870249d0564fcfa9a8f843589c5151ad",
    "key_index": 1,
    "quorum": 1,
    "raw_definition_byte": "",
    "type": "asset",
    "vm_version": 1,
    "xpubs": [
      "34b16ee500615cd325f8b84099f83c1ebecaca67977c5dc9b71ae32ceaf18207f996b0a9725b901d3792689b2babcb60febe3b81a684d9b56b65f67f307d453d"
    ]
  }
]

update-asset-alias

Parameters

Object:

  • String - id, id of asset.
  • String - alias, new alias of asset.
Returns

none if the asset alias is updated success.

Example

update asset alias.

// Request
new Asset.UpdateBuilder()
         .setAssetId(assetid)
         .setAlias(newAlias)
	 .update(client);

// Result

list-balances

Parameters

none

Returns
  • Array of Object, balances owned by the account.
    • Object:
      • String - account_id, account id.
      • String - account_alias, name of account.
      • String - asset_id, asset id.
      • String - asset_alias, name of asset.
      • Integer - amount, specified asset balance of account.
Example

list all the available account balances.

// Request
Balance.Items items = new Balance.QueryBuilder().list(client);

// Result
[
    {
      "account_alias": "default",
      "account_id": "0BDQ9AP100A02",
      "amount": 35508000000000,
      "asset_alias": "BTM",
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
    },
    {
      "account_alias": "alice",
      "account_id": "0BDQARM800A04",
      "amount": 60000000000,
      "asset_alias": "BTM",
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
    }
]

list-unspent-outputs

Parameters

Object:

optional:

  • String - id, id of unspent output.
Returns
  • Array of Object, unspent output array.
    • Object:
      • String - account_id, account id.
      • String - account_alias, name of account.
      • String - asset_id, asset id.
      • String - asset_alias, name of asset.
      • Integer - amount, specified asset balance of account.
      • String - address, address of account.
      • Boolean - change, whether the account address is change.
      • String - id, unspent output id.
      • String - program, program of account.
      • String - control_program_index, index of program.
      • String - source_id, source unspent output id.
      • String - source_pos, position of source unspent output id in block.
      • String - valid_height, valid height.
Example

list all the available unspent outputs:

// Request
UnspentOutput.Items items = new UnspentOutput.QueryBuilder()
                                             .setId("ffdc597f89349a1a19a74fd0811fd15c8fbbf384ce2bf3d17a718eddf9e79786")
					     .list(client);

// Result
[
  {
    "account_alias": "alice",
    "account_id": "0BKBR6VR00A06",
    "address": "bm1qv3htuvug7qdv46ywcvvzytrwrsyg0swltfa0dm",
    "amount": 2000,
    "asset_alias": "GOLD",
    "asset_id": "1883cce6aab82cf9af8cd085a3115dd4a92cdb8e6a9152acd73d7ae4adb9030a",
    "change": false,
    "control_program_index": 2,
    "id": "58f29f0f85f7bd2a91088bcbe536dee41cd0642dfb1480d3a88589bdbfd642d9",
    "program": "0014646ebe3388f01acae88ec318222c6e1c0887c1df",
    "source_id": "5988c1630c1f325e69bb92cb4b19af14286aa107311bc64b8f1a54629a33e0f4",
    "source_pos": 2,
    "valid_height": 0
  },
  {
    "account_alias": "default",
    "account_id": "0BKBR2D2G0A02",
    "address": "bm1qx7ylnhszg24995d5e0nftu9e87kt9vnxcn633r",
    "amount": 624000000000,
    "asset_alias": "BTM",
    "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
    "change": false,
    "control_program_index": 12,
    "id": "5af9d3c9b69470983377c1fc0c9125c4ac3bfd32c8d505f2a6042aade8503bc9",
    "program": "00143789f9de0242aa52d1b4cbe695f0b93facb2b266",
    "source_id": "233d1dd49e591980f98e11f333c6c28a867e78448e272011f045131df5aa260b",
    "source_pos": 0,
    "valid_height": 12
  }
]

build-transaction

Parameters

Object:

  • String - base_transaction, base data for the transaction.
  • Integer - ttl, integer of the time to live in seconds.
  • Arrary of Object - actions:
    • Object:
      • String - account_id | account_alias, alias or ID of account.
      • String - asset_id | asset_alias, alias or ID of asset.
      • Integer - amount, the specified asset of the amount sent with this transaction.
      • String- type, type of transaction, valid types: 'issue', 'spend', 'address'.
      • String - address, (type is address) address of receiver.
      • String - receiver, (type is spend) program of receiver.
Returns
  • Object of build-transaction - transaction, builded transaction.
Example
  • control_address - transaction type is control_address
//request
 client = TestUtils.generateClient();

		Transaction.Template controlAddress = new Transaction.Builder()
				.addAction(
						new Transaction.Action.SpendFromAccount()
								.setAccountId("0D00V8OUG0A02")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(300000000))
				.addAction(
						new Transaction.Action.ControlWithAddress()
								.setAddress("bm1qu5j0c0mcnzn6sy0um53t847wtkqa0nt785x4nh")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(200000000)).build(client);
// Result(this type is address, the other types are similar.)
{
	"raw_transaction" : "070100010161015f7feb07b6e782f3f62c4fbade202fd069299737fc345904faa8dcca0813d8464affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d5990100011600142c8d931da4bf895ca603c5820443767cb1c2bb81010002013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80d3bdc69801011600143bee3919e645af291efdd914e496aef72af76e8700013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8084af5f01160014e524fc3f7898a7a811fcdd22b3d7ce5d81d7cd7e00",
	"signing_instructions" : [ {
		"position" : 0,
		"witness_components" : [
				{
					"type" : "raw_tx_signature",
					"quorum" : 1,
					"keys" : [ {
						"xpub" : "2f3e45ed187bbc4f666f33f58a618af43c8154935312625ea4719734b202a3a20e6e38f266e0e70bff70786d53564e15a5418f51cc990e360425c8657e12c013",
						"derivation_path" : [ "010100000000000000",
								"0100000000000000" ]
					} ],
					"signatures" : null
				},
				{
					"type" : "data",
					"value" : "3f1e3abbf0837b4c52a9caf990b87c3cb2ea97d918970e62fca4453e13da75c0"
				} ]
	} ],
	"allow_additional_actions" : false
}}

sign-transaction

Parameters

Object:

  • String - password, signature of the password.
  • Object - transaction, builded transaction.
Returns

Object:

  • Boolean - sign_complete, returns true if sign succesfully and false otherwise.
  • Object of sign-transaction - transaction, signed transaction.
Example
// Request 
Transaction.Template controlAddress = new Transaction.Builder()
				.addAction(
						new Transaction.Action.SpendFromAccount()
								.setAccountId("0D00V8OUG0A02")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(300000000))
				.addAction(
						new Transaction.Action.ControlWithAddress()
								.setAddress("bm1qu5j0c0mcnzn6sy0um53t847wtkqa0nt785x4nh")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(200000000)).build(client);

		Transaction.Template singer = new Transaction.SignerBuilder().sign(client,
				controlAddress, "xxxxxx");
// Result(this type is address, the other types are similar.)
{
		"transaction" : {
			"raw_transaction" : "070100010161015f7feb07b6e782f3f62c4fbade202fd069299737fc345904faa8dcca0813d8464affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d5990100011600142c8d931da4bf895ca603c5820443767cb1c2bb81630240fc2a00960fad45fd28490a3a45679a6362ee4bd53a9da1d2edf3a354e7269cea32f2e05d1ff62fb14030187a058043dbc57d7a7bafccaa21847dd0ca4d2f980c203f1e3abbf0837b4c52a9caf990b87c3cb2ea97d918970e62fca4453e13da75c002013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80d3bdc698010116001402176f5cda77ea8c1a5a833a58f7a7755560cbe900013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8084af5f01160014e524fc3f7898a7a811fcdd22b3d7ce5d81d7cd7e00",
			"signing_instructions" : [ {
				"position" : 0,
				"witness_components" : [
						{
							"type" : "raw_tx_signature",
							"quorum" : 1,
							"keys" : [ {
								"xpub" : "2f3e45ed187bbc4f666f33f58a618af43c8154935312625ea4719734b202a3a20e6e38f266e0e70bff70786d53564e15a5418f51cc990e360425c8657e12c013",
								"derivation_path" : [ "010100000000000000",
										"0100000000000000" ]
							} ],
							"signatures" : [ "fc2a00960fad45fd28490a3a45679a6362ee4bd53a9da1d2edf3a354e7269cea32f2e05d1ff62fb14030187a058043dbc57d7a7bafccaa21847dd0ca4d2f980c" ]
						},
						{
							"type" : "data",
							"value" : "3f1e3abbf0837b4c52a9caf990b87c3cb2ea97d918970e62fca4453e13da75c0"
						} ]
			} ],
			"allow_additional_actions" : false
		},
		"sign_complete" : true
	}

submit-transaction

Parameters

Object:

  • Object - raw_transaction, raw_transaction of signed transaction.
Returns

Object:

  • String - tx_id, transaction id, hash of transaction.
Example
// Request

Transaction.Template controlAddress = new Transaction.Builder()
				.addAction(
						new Transaction.Action.SpendFromAccount()
								.setAccountId("0D00V8OUG0A02")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(300000000))
				.addAction(
						new Transaction.Action.ControlWithAddress()
								.setAddress("bm1qu5j0c0mcnzn6sy0um53t847wtkqa0nt785x4nh")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(200000000)).build(client);

		Transaction.Template singer = new Transaction.SignerBuilder().sign(client,
				controlAddress, "xxxxx");

		Transaction.SubmitResponse txs = Transaction.submit(client, singer); 
// Result
{"tx_id":"cb78aedfdad26cf7aad67f4e5776b916634daac3b66908523b78856bde6c2e6d"}

estimate-transaction-gas

Parameters

Object:

  • Object - transaction_template, builded transaction response.
Returns

Object:

  • Integer - total_neu, total consumed neu(1BTM = 10^8NEU) for execute transaction.
  • Integer - storage_neu, consumed neu for storage transaction .
  • Integer - vm_neu, consumed neu for execute VM.
Example
// Request
Transaction.Template controlAddress = new Transaction.Builder()
				.addAction(
						new Transaction.Action.SpendFromAccount()
								.setAccountId("0D00V8OUG0A02")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(300000000))
				.addAction(
						new Transaction.Action.ControlWithAddress()
								.setAddress("bm1qu5j0c0mcnzn6sy0um53t847wtkqa0nt785x4nh")
								.setAssetId(
										"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
								.setAmount(200000000)).build(client);	
		TransactionGas gas= Transaction.estimateGas(client, controlAddress);
// Result
{
		"total_neu" : 437400,
		"storage_neu" : 153600,
		"vm_neu" : 283800
}

get-transaction

Parameters

Object:

  • String - tx_id, transaction id, hash of transaction.
Returns

Object:

  • Integer - block_height, block height where this transaction was in.
  • String - block_hash, hash of the block where this transaction was in.
  • String - block_transactions_count, transaction count where this transaction was in the block.
  • String - tx_id, transaction id, hash of the transaction.
  • Integer - block_index, position of the transaction in the block.
  • Boolean - status_fail, whether the state of the request has failed.
  • String - block_time, the unix timestamp for when the requst was responsed.
  • Integer - size, size of transaction.
  • Array of Object - inputs, object of inputs for the transaction.
    • String - type, the type of input action, available option include: 'spend', 'issue', 'coinbase'.
    • String - asset_id, asset id.
    • String - asset_alias, name of asset.
    • Object - asset_definition, definition of asset(json object).
    • Integer - amount, amount of asset.
    • String - issuance_program, issuance program, it only exist when type is 'issue'.
    • String - control_program, control program, it only exist when type is 'spend'.
    • String - address, address of account.
    • String - spent_output_id, the front of SpentOutputID, it only exist when type is 'spend'.
    • String - account_id, account id.
    • String - account_alias, name of account.
    • String - arbitrary, arbitrary infomation can be set by miner, it only exist when type is 'coinbase'.
  • Array of Object - outputs, object of outputs for the transaction.
    • String - type, the type of output action, available option include: 'retire', 'control'.
    • String - id, outputid related to utxo.
    • String - position, position of outputs.
    • String - asset_id, asset id.
    • String - asset_alias, name of asset.
    • Object - asset_definition, definition of asset(json object).
    • Integer - amount, amount of asset.
    • String - account_id, account id.
    • String - account_alias, name of account.
    • String - control_program, control program of account.
    • String - address, address of account.
Example
// Request
Transaction tran = new Transaction.QueryBuilder()
                                .setTxId("f4f1cd86b75c74159b32a70f3b6d486fa1ee6d7c3fd654a01b351f38236da32b")
				.get(client);

		Transaction.Input input = tran.inputs.get(0);
		Transaction.Output output = tran.outputs.get(0);
// Result
{
		"tx_id" : "f4f1cd86b75c74159b32a70f3b6d486fa1ee6d7c3fd654a01b351f38236da32b",
		"block_time" : 1524555187,
		"block_hash" : "a4ab32b3c6daaaec825852653de5d50b249019f226e1755737633fe49e7c1d18",
		"block_height" : 39,
		"block_index" : 0,
		"block_transactions_count" : 1,
		"inputs" : [ {
			"type" : "coinbase",
			"asset_id" : "0000000000000000000000000000000000000000000000000000000000000000",
			"asset_definition" : {},
			"amount" : 0,
			"arbitrary" : "27"
		} ],
		"outputs" : [ {
			"type" : "control",
			"id" : "f8e79f35e7604896eaca878ef4aeb509a041ff7e2859b105a00240ed52dd1025",
			"position" : 0,
			"asset_id" : "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
			"asset_definition" : {},
			"amount" : 41250000000,
			"account_id" : "0D00V8OUG0A02",
			"account_alias" : "bytommaster",
			"control_program" : "00142c8d931da4bf895ca603c5820443767cb1c2bb81",
			"address" : "bm1q9jxex8dyh7y4efsrckpqgsmk0jcu9wup684a9y"
		} ],
		"status_fail" : false
	}

list-transactions

Parameters

Object:

optional:

  • String - tx_id, transaction id, hash of transaction.
  • String - account_id, id of account.
  • Bool - detail , flag of required transactions data ,default false (only return transaction summary)
Returns

Array of Object, transaction array.

optional:

  • Object:(summary transaction)

    • String - tx_id, transaction id, hash of the transaction.
    • String - block_time, the unix timestamp for when the requst was responsed.
    • Array of Object - inputs, object of inputs for the transaction.
    • Array of Object - outputs, object of outputs for the transaction.
  • Object:(detail transaction)

    • Integer - block_height, block height where this transaction was in.
    • String - block_hash, hash of the block where this transaction was in.
    • String - block_transactions_count, transaction count where this transaction was in the block.
    • String - tx_id, transaction id, hash of the transaction.
    • Integer - block_index, position of the transaction in the block.
    • Boolean - status_fail, whether the state of the request has failed.
    • String - block_time, the unix timestamp for when the requst was responsed.
    • Integer - size, size of transaction.
    • Array of Object - inputs, object of inputs for the transaction.
    • Array of Object - outputs, object of outputs for the transaction.
Example

list all the available transactions:

// Request
Transaction.Items items = new Transaction.QueryBuilder().list(client);
// Result
[
  {
    "block_time": 1521771059,
    "inputs": [
      {
        "arbitrary": "c4a4",
        "asset_id": "0000000000000000000000000000000000000000000000000000000000000000",
        "type": "coinbase"
      }
    ],
    "outputs": [
      {
        "account_alias": "default",
        "account_id": "0BMHBOBVG0A02",
        "amount": 624000000000,
        "asset_alias": "btm",
        "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "type": "control"
      }
    ],
    "tx_id": "c631a8de401913a512c338bcf4a61cb2de6cede12a7385d9d11637eaa6578f33"
  },
  {
    "block_time": 1521770515,
    "inputs": [
      {
        "account_alias": "default",
        "account_id": "0BMHBOBVG0A02",
        "amount": 624000000000,
        "asset_alias": "btm",
        "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "type": "spend"
      }
    ],
    "outputs": [
      {
        "account_alias": "default",
        "account_id": "0BMHBOBVG0A02",
        "amount": 563980000000,
        "asset_alias": "btm",
        "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "type": "control"
      },
      {
        "account_alias": "alice",
        "account_id": "0BMHDI1P00A04",
        "amount": 60000000000,
        "asset_alias": "btm",
        "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "type": "control"
      }
    ],
    "tx_id": "1151ce5c7b32b8755b5e48109ec7ed956fb1783eaea9558bf5a2ad957825e4b7"
  }
]

backup-wallet

Parameters

none

Returns

Object:

  • Object - account_image, account image.
  • Object - asset_image, asset image.
  • Object - key_images, key image.
Example
// Request
Wallet w = Wallet.backupWallet(client);

// Result
{
  "account_image": {
    "slices": [
      {
        "account": {
          "type": "account",
          "xpubs": [
            "395d6e0ac25978c3f52f9c7bdfdf75ce6af02639fd7875b4b1f40778ab1120c6dcf461b7ab6fd310983afb54a9a0fb3e09b6ec0d4364c4808c94383d50fb0681"
          ],
          "quorum": 1,
          "key_index": 1,
          "ID": "0CQTA3EOG0A02",
          "Alias": "def"
        },
        "contract_index": 2
      }
    ]
  },
  "asset_image": {
    "assets": []
  },
  "key_images": {
    "xkeys": [
      {
        "crypto": {
          "cipher": "aes-128-ctr",
          "ciphertext": "bf44766fec149478af9500e25ce0a6bc50bb2fa04e40465781da6ff64e9b3a4c9af3d214cd92c5a41d8498db5f4376526740f960ff429b16e52876aec6860e1d",
          "cipherparams": {
            "iv": "1b0fc61ae4dacb15f0f77d2b4ba67635"
          },
          "kdf": "scrypt",
          "kdfparams": {
            "dklen": 32,
            "n": 4096,
            "p": 6,
            "r": 8,
            "salt": "e133b1e7caae771ff1ab34b14824d6e27ef399f2b7ded4ad3500f080ede4a1dd"
          },
          "mac": "bc6bf411fb63e61a17bc15b94f29cf0d5a0f084c328955da1f7e2b26757cfc23"
        },
        "id": "1f40be59-7400-4fdc-b46b-15009f65363a",
        "type": "bytom_kd",
        "version": 1,
        "alias": "default",
        "xpub": "c4ec9bfd5df19d175e17ff7fed89193c37a4a64e1c0928387da01387ca76c3bfd99390e3373ec4d438522cc2d4644214cd2ec3b00965f7a1fa3546809583191c"
      },
      {
        "crypto": {
          "cipher": "aes-128-ctr",
          "ciphertext": "f0887c8603cbbafc0a66d5b45f71488e089708c7dea4342625a67858a49d6d08c79cd3f1800627e3c8b4668e8df34fcf0be9df5d9d4503acff05373976c312a9",
          "cipherparams": {
            "iv": "c111b46f9104f49f2c40aedb827e53b5"
          },
          "kdf": "scrypt",
          "kdfparams": {
            "dklen": 32,
            "n": 4096,
            "p": 6,
            "r": 8,
            "salt": "d9ef588b258b111dea1d99a4e4c5a4f968ab69072176bb95b111922e3bbea9e6"
          },
          "mac": "336f5fee643776e139f05ebe5e4f209d992ff97e16b906105fadac9e86133554"
        },
        "id": "611d407c-9e97-4297-a02a-13cd68e47983",
        "type": "bytom_kd",
        "version": 1,
        "alias": "def",
        "xpub": "395d6e0ac25978c3f52f9c7bdfdf75ce6af02639fd7875b4b1f40778ab1120c6dcf461b7ab6fd310983afb54a9a0fb3e09b6ec0d4364c4808c94383d50fb0681"
      }
    ]
  }
}

restore-wallet

Parameters

Object:

  • Object - account_image, account image.
  • Object - asset_image, asset image.
  • Object - key_images, key image.
Returns

none if restore wallet success.

Example
// Request
Wallet w = Wallet.backupWallet(client);
Wallet.restoreWallet(client, w.accountImage, w.assetImage, w.keyImages);

// Result

sign-message

Parameters

Object:

  • String - address, address for account.
  • String - message, message for signature by address xpub.
  • String - password, password of account.
Returns

Object:

  • String - derived_xpub, derived xpub.
  • String - signature, signature of message.
Example
// Request
Message message = new Message.SignBuilder()
                             .setAddress("bm1q9jxex8dyh7y4efsrckpqgsmk0jcu9wup684a9y")
			     .setMessage("this is a test message")
			     .setPassword("xxxxx@pwd")
			     .sign(client);  

// Result
{
  "signature": "74da3d6572233736e3a439166719244dab57dd0047f8751b1efa2da26eeab251d915c1211dcad77e8b013267b86d96e91ae67ff0be520ef4ec326e911410b609",
  "derived_xpub": "6ff8c3d1321ce39a3c3550f57ba70b67dcbcef821e9b85f6150edb7f2f3f91009e67f3075e6e76ed5f657ee4b1a5f4749b7a8c74c8e7e6a1b0e5918ebd5df4d0"
}

create-access-token

Parameters

Object:

  • String - id, token ID.

optional:

  • String - type, type of token.
Returns

Object:

  • String - token, access token.
  • String - id, token ID.
  • String - type, type of token.
  • Object - created_at, time to create token.
Example

create access token.

// Request
Token t = new Token.Builder().setId(id).create(client);

// Result
{
  "token": "token1:1fee70f537128a201338bd5f25a3adbf33dad02eae4f4c9ac43f336a069df8f3",
  "id": "token1",
  "created_at": "2018-03-20T18:56:01.043919771+08:00"
}

list-access-tokens

Parameters

none

Returns
  • Array of Object, access token array.
    • Object:
      • String - token, access token.
      • String - id, token ID.
      • String - type, type of token.
      • Object - created_at, time to create token.
Example

list all the available access tokens.

// Request
Token.Items items = Token.list(client);

// Result
[
  {
    "token": "token1:1fee70f537128a201338bd5f25a3adbf33dad02eae4f4c9ac43f336a069df8f3",
    "id": "token1",
    "created_at": "2018-03-20T18:56:01.043919771+08:00"
  },
  {
    "token": "alice:78598c6d9fb9e3258d01f78005d4e5725ad0d45e20af90a30b577b407d4a2edd",
    "id": "alice",
    "created_at": "2018-03-20T18:56:01.043919771+08:00"
  }
]

delete-access-token

Parameters

Object:

  • String - id, token ID.
Returns

Boolen - flag, success return true.

Example

delete access token.

// Request
boolean flag = Token.delete(client, id);

// Result
true

check-access-token

Parameters

Object:

  • String - id, token ID.
  • String - secret, secret of token, the second part of the colon division for token.
Returns

Boolen - flag, success return true.

Example

check whether the access token is vaild or not.

// Request
boolean flag = Token.check(client, id, secret);

// Result
true

create-transaction-feed

Parameters

Object:

  • String - alias, name of the transaction feed.
  • String - filter, filter of the transaction feed.
Returns

Boolen - flag, success return true.

Example
// Request
boolean flag = new TransactionFeed.Builder().setAlias("test1")
                                            .setFilter("asset_id='84778a666fe453cf73b2e8c783dbc9e04bc4fd7cbb4f50caeaee99cf9967ebed' AND amount_lower_limit = 50 AND amount_upper_limit = 100")
					    .create(client);

// Result
true

get-transaction-feed

Parameters

Object:

  • String - alias, name of the transaction feed.
Returns

Object:

  • String - id, id of the transaction feed.
  • String - alias, name of the transaction feed.
  • String - filter, filter of the transaction feed.
  • Object - param, param of the transaction feed.
    • String - assetid, asset id.
    • Integer - lowerlimit, the lower limit of asset amount.
    • Integer - upperlimit, the upper limit of asset amount.
    • String - transtype, type of transaction.
Example

list the available tx

Clone this wiki locally