1 # Java SDK documentation
3 This page will document the API classes and ways to properly use the API.
4 Subsequent new releases also maintain backward compatibility with this class approach.
9 public static Client generateClient() throws BytomException {
10 String coreURL = Configuration.getValue("bytom.api.url");
11 String accessToken = Configuration.getValue("client.access.token");
12 if (coreURL == null || coreURL.isEmpty()) {
13 coreURL = "http://127.0.0.1:9888/";
15 return new Client(coreURL, accessToken);
18 Client client = TestUtils.generateClient();
23 * [`Step 1: Create a key`](#create-a-key)
24 * [`Step 2: Create an account`](#create-an-account)
25 * [`Step 3: Create an receiver`](#create-an-receiver)
26 * [`Step 4: Create an asset`](#create-an-asset)
27 * [`Step 5: Issue asset`](#issue-asset)
28 * [`Firstly build the transaction`](#firstly-build-the-transaction)
29 * [`Secondly sign the transaction`](#secondly-sign-the-transaction)
30 * [`Finally submit the transaction`](#finally-submit-the-transaction)
32 > For more details, see [`API methods`](#api-methods)
37 String alias = "test";
38 String password = "123456";
40 Key.Builder builder = new Key.Builder().setAlias(alias).setPassword(password);
41 Key key = Key.create(client, builder);
47 String alias = "sender-account";
49 List<String> root_xpubs = new ArrayList<String>();
50 root_xpubs.add(senderKey.xpub);
52 Account.Builder builder = new Account.Builder().setAlias(alias).setQuorum(quorum).setRootXpub(root_xpubs);
54 Account account = Account.create(client, builder);
60 String alias = receiverAccount.alias;
61 String id = receiverAccount.id;
63 Account.ReceiverBuilder receiverBuilder = new Account.ReceiverBuilder().setAccountAlias(alias).setAccountId(id);
64 Receiver receiver = receiverBuilder.create(client);
70 String alias = "receiver-asset";
72 List<String> xpubs = receiverAccount.xpubs;
74 Asset.Builder builder = new Asset.Builder()
78 receiverAsset = builder.create(client);
83 ### Firstly build the transaction
86 Transaction.Template controlAddress = new Transaction.Builder()
88 new Transaction.Action.SpendFromAccount()
89 .setAccountId(senderAccount.id)
90 .setAssetId(senderAsset.id)
94 new Transaction.Action.ControlWithAddress()
95 .setAddress(receiverAddress.address)
96 .setAssetId(senderAsset.id)
101 ### Secondly sign the transaction
104 Transaction.Template singer = new Transaction.SignerBuilder().sign(client,
105 controlAddress, "123456");
108 ### Finally submit the transaction
111 Transaction.SubmitResponse txs = Transaction.submit(client, singer);
118 * [`Key API`](#key-api)
119 * [`Account API`](#account-api)
120 * [`Asset API`](#asset-api)
121 * [`Transaction API`](#transaction-api)
122 * [`Wallet API`](#wallet-api)
123 * [`Access Token API`](#access-token-api)
124 * [`Block API`](#block-api)
125 * [`Other API`](#other-api)
133 Key create(Client client, Builder builder);
138 - `Client` - *client*, Client object that makes requests to the core.
139 - `Key.Builder` - *builder*, Builder object that builds request parameters.
143 - `Key` - *key*, Key object.
150 List<Key> list(Client client);
155 - `Client` - *client*, Client object that makes requests to the core.
159 - `List of Key`, *List<Key>*, an ArrayList object contains Key objects.
166 void delete(Client client, String xpub, String password);
171 - `Client` - *client*, Client object that makes requests to the core.
172 - `String` - *xpub*, pubkey of the key.
173 - `String` - *password*, password of the key.
177 none if the key is deleted successfully.
181 #### 4.resetKeyPassword
184 void resetPwd(Client client, String xpub, String oldPwd, String newPwd);
189 - `Client` - *client*, Client object that makes requests to the core.
190 - `String` - *xpub*, pubkey of the key.
191 - `String` - *oldPwd*, old password of the key.
192 - `String` - *newPwd*, new password of the key.
196 none if the key password is reset successfully.
205 Account create(Client client, Builder builder);
209 - `Client` - *client*, Client object that makes requests to the core.
210 - `Account.Builder` - *builder*, Builder object that builds request parameters.
214 - `Account` - *account*, Account object.
221 List<Account> list(Client client);
226 - `Client` - *client*, Client object that makes requests to the core.
230 - `List of Account`, *List<Account>*, an ArrayList object contains Account objects.
237 void delete(Client client, String account_info);
242 - `Client` - *client*, Client object that makes requests to the core.
243 - `String` - *account_info*, alias or ID of account.
247 none if the account is deleted successfully.
251 #### 4.createAccountReceiver
254 Receiver create(Client client);
259 - `Client` - *client*, Client object that makes requests to the core.
263 - `Receiver` - *receiver*, Receiver object.
271 List<Address> list(Client client);
276 - `Client` - *client*, Client object that makes requests to the core.
280 - `List of Address`, *List<Address>*, an ArrayList object contains Address objects.
284 #### 6.validateAddress
287 Address validate(Client client, String address);
292 - `Client` - *Client*, Client object that makes requests to the core.
293 - `String` - *address*, address of account.
297 - `Address` - *address*, an Address object.
306 Asset create(Client client);
311 - `Client` - *Client*, Client object that makes requests to the core.
315 - `Asset` - *asset*, an Asset object.
322 Asset get(Client client);
327 - `Client` - *Client*, Client object that makes requests to the core.
331 - `Asset` - *asset*, an Asset object.
338 List<Asset> list(Client client);
343 - `Client` - *Client*, Client object that makes requests to the core.
347 - `List of Asset`, *List<Asset>*, an ArrayList object contains Asset objects.
351 #### 4.updateAssetAlias
354 void update(Client client);
359 - `Client` - *Client*, Client object that makes requests to the core.
363 none if the asset alias is updated success.
370 List<Balance> list(Client client);
375 - `Client` - *Client*, Client object that makes requests to the core.
379 - `List of Balance`, an ArrayList object contains Balance objects.
383 #### 6.listUnspentOutPuts
386 List<UnspentOutput> list(Client client);
391 - `Client` - *Client*, Client object that makes requests to the core.
395 - `List of UnspentOutput`, an ArrayList object contains UnspentOutput objects.
401 #### buildTransaction
404 Template build(Client client);
409 - `Client` - *Client*, Client object that makes requests to the core.
413 - `Template` - *template*, a template object.
420 Template sign(Client client, Template template, String password);
427 - `Client` - *Client*, Client object that makes requests to the core.
428 - `Template` - *template*, a template object.
429 - `String` - *password*, signature of the password.
433 - `Template` - *template*, a template object.
437 #### submitTransaction
440 SubmitResponse submit(Client client, Template template);
445 - `Client` - *Client*, Client object that makes requests to the core.
446 - `Template` - *template*, a template object.
450 - `SubmitResponse` - *submitResponse*, a SubmitResponse object
454 #### estimateTransactionGas
457 TransactionGas estimateGas(Client client, Template template);
462 - `Client` - *Client*, Client object that makes requests to the core.
463 - `Template` - *template*, a template object.
467 - `TransactionGas` - *transactionGas*, a TransactionGas object
474 Transaction get(Client client);
479 - `Client` - *Client*, Client object that makes requests to the core.
483 - `Transaction` - *transaction*, a Transaction object
487 #### listTransactions
490 List<Transaction> list(Client client);
495 - `Client` - *Client*, Client object that makes requests to the core.
499 - `List of Transaction`, *List<Transaction>*, an ArrayList object contains Transaction objects.
504 //list all transactions
505 List<Transaction> transactionList = new Transaction.QueryBuilder().list(client);
510 #### listTransactionsById
513 List<Transaction> listById(Client client);
518 - `Client` - *Client*, Client object that makes requests to the core.
522 - `List of Transaction`, *List<Transaction>*, an ArrayList object contains Transaction objects.
527 String tx_id = "f04d4d9b2580ff6496f9f08d903de5a2365975fb8d65b66ca4259f152c5dd134";
528 //list all transactions by tx_id
529 List<Transaction> transactionList = new Transaction.QueryBuilder().setTxId(tx_id).list(client);
534 #### listTransactionsByAccountId
537 List<Transaction> listByAccountId(Client client);
542 - `Client` - *Client*, Client object that makes requests to the core.
546 - `List of Transaction`, *List<Transaction>*, an ArrayList object contains Transaction objects.
551 String account_id = "0E6KP8C100A02";
552 //list all transactions by account_id
553 List<Transaction> transactionList = new Transaction.QueryBuilder().setAccountId(account_id).list(client);
562 Wallet backupWallet(Client client);
567 - `Client` - *Client*, Client object that makes requests to the core.
571 - `Wallet` - *wallet*, a Wallet object
578 void restoreWallet(Client client ,Object accountImage, Object assetImage , Object keyImages);
584 - `Client` - *Client*, Client object that makes requests to the core.
585 - `Object` - *account_image*, account image.
586 - `Object` - *asset_image*, asset image.
587 - `Object` - *key_images*, key image.
591 none if restore wallet success.
598 AccessToken accessToken = new AccessToken.Builder().setId("sheng").create(client);
600 List<AccessToken> tokenList = AccessToken.list(client);
602 String secret = "5e37378eb59de6b10e60f2247ebf71c4955002e75e0cd31ede3bf48813a0a799";
603 AccessToken.check(client, "sheng", secret);
606 #### createAccessToken
609 AccessToken create(Client client);
614 - `Client` - *Client*, Client object that makes requests to the core.
618 - `AccessToken` - *accessToken*, an AccessToken object.
622 #### listAccessTokens
625 List<AccessToken> list(Client client);
630 - `Client` - *Client*, Client object that makes requests to the core.
634 - `Array of Object`, access token array.
638 #### deleteAccessToken
641 void delete(Client client, String id);
646 - `Client` - *Client*, Client object that makes requests to the core.
647 - `String` - *id*, token ID.
651 none if the access token is deleted successfully.
655 #### checkAccessToken
658 void check(Client client, String id, String secret);
663 - `Client` - *Client*, Client object that makes requests to the core.
664 - `String` - *id*, token ID.
665 - `String` - *secret*, secret of token, the second part of the colon division for token.
669 none if the access token is checked valid.
678 Integer getBlockCount(Client client);
687 - `Integer` - *block_count*, recent block height of the blockchain.
694 String getBlockHash(Client client);
703 - `String` - *block_hash*, recent block hash of the blockchain.
709 Block getBlock(Client client);
714 - `Client` - *Client*, Client object that makes requests to the core.
718 - `Block` - *block*, a Block object.
725 BlockHeader getBlockHeader(Client client);
730 - `Client` - *Client*, Client object that makes requests to the core.
734 - `BlockHeader` - *blockHeader*, header of block.
741 BlockDifficulty getBlockDifficulty(Client client);
746 - `Client` - *Client*, Client object that makes requests to the core.
750 - `BlockDifficulty` - *blockDifficulty*, a BlockDifficulty object
757 BlockHashRate getHashRate(Client client);
762 - `Client` - *Client*, Client object that makes requests to the core.
766 - `BlockHashRate` - *blockHashRate*, a BlockHashRate object
775 NetInfo getNetInfo(Client client);
780 - `Client` - *Client*, Client object that makes requests to the core.
784 - `NetInfo` - *netInfo*, a NetInfo object.
791 Gas gasRate(Client client);
796 - `Client` - *Client*, Client object that makes requests to the core.
800 - `Gas` - *gas*, a Gas object.
807 Boolean verifyMessage(Client client);
812 - `Client` - *Client*, Client object that makes requests to the core.
816 - `Boolean` - *result*, verify result.