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 * [`Mining API`](#mining-api)
126 * [`Other API`](#other-api)
134 Key create(Client client, Builder builder);
139 - `Client` - *client*, Client object that makes requests to the core.
140 - `Key.Builder` - *builder*, Builder object that builds request parameters.
144 - `Key` - *key*, Key object.
151 List<Key> list(Client client);
156 - `Client` - *client*, Client object that makes requests to the core.
160 - `List of Key`, *List<Key>*, an ArrayList object contains Key objects.
167 void delete(Client client, String xpub, String password);
172 - `Client` - *client*, Client object that makes requests to the core.
173 - `String` - *xpub*, pubkey of the key.
174 - `String` - *password*, password of the key.
178 none if the key is deleted successfully.
182 #### resetKeyPassword
185 void resetPwd(Client client, String xpub, String oldPwd, String newPwd);
190 - `Client` - *client*, Client object that makes requests to the core.
191 - `String` - *xpub*, pubkey of the key.
192 - `String` - *oldPwd*, old password of the key.
193 - `String` - *newPwd*, new password of the key.
197 none if the key password is reset successfully.
206 Account create(Client client, Builder builder);
210 - `Client` - *client*, Client object that makes requests to the core.
211 - `Account.Builder` - *builder*, Builder object that builds request parameters.
215 - `Account` - *account*, Account object.
222 List<Account> list(Client client);
227 - `Client` - *client*, Client object that makes requests to the core.
231 - `List of Account`, *List<Account>*, an ArrayList object contains Account objects.
238 void delete(Client client, String account_info);
243 - `Client` - *client*, Client object that makes requests to the core.
244 - `String` - *account_info*, alias or ID of account.
248 none if the account is deleted successfully.
252 #### createAccountReceiver
255 Receiver create(Client client);
260 - `Client` - *client*, Client object that makes requests to the core.
264 - `Receiver` - *receiver*, Receiver object.
272 List<Address> list(Client client);
277 - `Client` - *client*, Client object that makes requests to the core.
281 - `List of Address`, *List<Address>*, an ArrayList object contains Address objects.
288 Address validate(Client client, String address);
293 - `Client` - *Client*, Client object that makes requests to the core.
294 - `String` - *address*, address of account.
298 - `Address` - *address*, an Address object.
307 Asset create(Client client);
312 - `Client` - *Client*, Client object that makes requests to the core.
316 - `Asset` - *asset*, an Asset object.
323 Asset get(Client client);
328 - `Client` - *Client*, Client object that makes requests to the core.
332 - `Asset` - *asset*, an Asset object.
339 List<Asset> list(Client client);
344 - `Client` - *Client*, Client object that makes requests to the core.
348 - `List of Asset`, *List<Asset>*, an ArrayList object contains Asset objects.
352 #### updateAssetAlias
355 void update(Client client);
360 - `Client` - *Client*, Client object that makes requests to the core.
364 none if the asset alias is updated success.
371 List<Balance> list(Client client);
376 - `Client` - *Client*, Client object that makes requests to the core.
380 - `List of Balance`, an ArrayList object contains Balance objects.
384 #### listUnspentOutPuts
387 List<UnspentOutput> list(Client client);
392 - `Client` - *Client*, Client object that makes requests to the core.
396 - `List of UnspentOutput`, an ArrayList object contains UnspentOutput objects.
402 #### buildTransaction
405 Template build(Client client);
410 - `Client` - *Client*, Client object that makes requests to the core.
414 - `Template` - *template*, a template object.
421 Template sign(Client client, Template template, String password);
428 - `Client` - *Client*, Client object that makes requests to the core.
429 - `Template` - *template*, a template object.
430 - `String` - *password*, signature of the password.
434 - `Template` - *template*, a template object.
438 #### submitTransaction
441 SubmitResponse submit(Client client, Template template);
446 - `Client` - *Client*, Client object that makes requests to the core.
447 - `Template` - *template*, a template object.
451 - `SubmitResponse` - *submitResponse*, a SubmitResponse object
455 #### estimateTransactionGas
458 TransactionGas estimateGas(Client client, Template template);
463 - `Client` - *Client*, Client object that makes requests to the core.
464 - `Template` - *template*, a template object.
468 - `TransactionGas` - *transactionGas*, a TransactionGas object
475 Transaction get(Client client);
480 - `Client` - *Client*, Client object that makes requests to the core.
484 - `Transaction` - *transaction*, a Transaction object
488 #### listTransactions
491 List<Transaction> list(Client client);
496 - `Client` - *Client*, Client object that makes requests to the core.
500 - `List of Transaction`, *List<Transaction>*, an ArrayList object contains Transaction objects.
508 Wallet backupWallet(Client client);
513 - `Client` - *Client*, Client object that makes requests to the core.
517 - `Wallet` - *wallet*, a Wallet object
524 void restoreWallet(Client client ,Object accountImage, Object assetImage , Object keyImages);
530 - `Client` - *Client*, Client object that makes requests to the core.
531 - `Object` - *account_image*, account image.
532 - `Object` - *asset_image*, asset image.
533 - `Object` - *key_images*, key image.
537 none if restore wallet success.
544 AccessToken accessToken = new AccessToken.Builder().setId("sheng").create(client);
546 List<AccessToken> tokenList = AccessToken.list(client);
548 String secret = "5e37378eb59de6b10e60f2247ebf71c4955002e75e0cd31ede3bf48813a0a799";
549 AccessToken.check(client, "sheng", secret);
552 #### createAccessToken
555 AccessToken create(Client client);
560 - `Client` - *Client*, Client object that makes requests to the core.
564 - `AccessToken` - *accessToken*, an AccessToken object.
568 #### listAccessTokens
571 List<AccessToken> list(Client client);
576 - `Client` - *Client*, Client object that makes requests to the core.
580 - `Array of Object`, access token array.
584 #### deleteAccessToken
587 void delete(Client client, String id);
592 - `Client` - *Client*, Client object that makes requests to the core.
593 - `String` - *id*, token ID.
597 none if the access token is deleted successfully.
601 #### checkAccessToken
604 void check(Client client, String id, String secret);
609 - `Client` - *Client*, Client object that makes requests to the core.
610 - `String` - *id*, token ID.
611 - `String` - *secret*, secret of token, the second part of the colon division for token.
615 none if the access token is checked valid.
624 Integer getBlockCount(Client client);
633 - `Integer` - *block_count*, recent block height of the blockchain.
640 String getBlockHash(Client client);
649 - `String` - *block_hash*, recent block hash of the blockchain.
655 Block getBlock(Client client);
660 - `Client` - *Client*, Client object that makes requests to the core.
664 - `Block` - *block*, a Block object.
671 BlockHeader getBlockHeader(Client client);
676 - `Client` - *Client*, Client object that makes requests to the core.
680 - `BlockHeader` - *blockHeader*, header of block.
687 BlockDifficulty getBlockDifficulty(Client client);
692 - `Client` - *Client*, Client object that makes requests to the core.
696 - `BlockDifficulty` - *blockDifficulty*, a BlockDifficulty object
703 BlockHashRate getHashRate(Client client);
708 - `Client` - *Client*, Client object that makes requests to the core.
712 - `BlockHashRate` - *blockHashRate*, a BlockHashRate object
720 Boolean isMining(Client client);
725 - `Client` - *Client*, Client object that makes requests to the core.
729 - `Boolean` - *is_mining*, whether the node is mining.
736 void setMining(Client client, Boolean isMining);
741 - `Client` - *Client*, Client object that makes requests to the core.
742 - `Boolean` - *is_mining*, whether the node is mining.
751 NetInfo getNetInfo(Client client);
756 - `Client` - *Client*, Client object that makes requests to the core.
760 - `NetInfo` - *netInfo*, a NetInfo object.
767 Gas gasRate(Client client);
772 - `Client` - *Client*, Client object that makes requests to the core.
776 - `Gas` - *gas*, a Gas object.
783 Boolean verifyMessage(Client client);
788 - `Client` - *Client*, Client object that makes requests to the core.
792 - `Boolean` - *result*, verify result.
799 MinerWork getWork(Client client);
804 - `Client` - *Client*, Client object that makes requests to the core.
808 - `MinerWork` - *minerWork*, a MinerWork object.
815 void submiWork(Client client, String blockHeader);
820 - `Client` - *Client*, Client object that makes requests to the core.
821 - `String` - *block_header*, raw block header.
825 none if the work is submitted successfully.