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
5 approach. For more information, please see Bytom API reference documentation
6 at [Bytom wiki](https://github.com/Bytom/bytom/wiki/API-Reference)
10 There are various ways to install and use this sdk. We'll provide three ways to get it. Note that the bytom-sdk requires JAVA 7 or newer.
16 <groupId>io.bytom</groupId>
17 <artifactId>java-sdk</artifactId>
18 <version>1.0.0</version>
24 compile 'io.bytom:bytom-sdk:1.0.1'
27 ### Building from source code
29 To clone, compile, and install in your local maven repository (or copy the artifacts from the target/ directory to wherever you need them):
32 git clone https://github.com/Bytom/bytom-java-sdk.git
34 mvn package -Dmaven.test.skip=true
41 public static Client generateClient() throws BytomException {
42 String coreURL = Configuration.getValue("bytom.api.url");
43 String accessToken = Configuration.getValue("client.access.token");
44 if (coreURL == null || coreURL.isEmpty()) {
45 coreURL = "http://127.0.0.1:9888/";
47 return new Client(coreURL, accessToken);
50 Client client = Client.generateClient();
52 > Note: you can touch a file named ```config.properties``` in resources folder to config ```bytom.api.url``` and ```client.access.token``` by custom.
56 * [`Step 1: Create a key`](#create-a-key)
57 * [`Step 2: Create an account`](#create-an-account)
58 * [`Step 3: Create an receiver`](#create-an-receiver)
59 * [`Step 4: Create an asset`](#create-an-asset)
60 * [`Step 5: Issue asset`](#issue-asset)
61 * [`Firstly build the transaction`](#firstly-build-the-transaction)
62 * [`Secondly sign the transaction`](#secondly-sign-the-transaction)
63 * [`Finally submit the transaction`](#finally-submit-the-transaction)
65 > For more details, see [API methods](https://github.com/Bytom/java-sdk/blob/master/doc/index.md#api-methods)
70 String alias = "test";
71 String password = "123456";
73 Key.Builder builder = new Key.Builder().setAlias(alias).setPassword(password);
74 Key key = Key.create(client, builder);
80 String alias = "sender-account";
82 List<String> root_xpubs = new ArrayList<String>();
83 root_xpubs.add(senderKey.xpub);
85 Account.Builder builder = new Account.Builder().setAlias(alias).setQuorum(quorum).setRootXpub(root_xpubs);
87 Account account = Account.create(client, builder);
90 ### Create an receiver
93 String alias = receiverAccount.alias;
94 String id = receiverAccount.id;
96 Account.ReceiverBuilder receiverBuilder = new Account.ReceiverBuilder().setAccountAlias(alias).setAccountId(id);
97 Receiver receiver = receiverBuilder.create(client);
103 String alias = "receiver-asset";
105 List<String> xpubs = receiverAccount.xpubs;
107 Asset.Builder builder = new Asset.Builder()
110 .setRootXpubs(xpubs);
111 receiverAsset = builder.create(client);
116 For more transaction details, see [transactions](https://github.com/Bytom/java-sdk/blob/master/doc/transactions.md)
118 #### Firstly build the transaction
121 Transaction.Template controlAddress = new Transaction.Builder()
123 new Transaction.Action.SpendFromAccount()
124 .setAccountId(senderAccount.id)
125 .setAssetId(senderAsset.id)
126 .setAmount(300000000)
129 new Transaction.Action.ControlWithAddress()
130 .setAddress(receiverAddress.address)
131 .setAssetId(senderAsset.id)
132 .setAmount(200000000)
136 #### Secondly sign the transaction
139 Transaction.Template singer = new Transaction.SignerBuilder().sign(client,
140 controlAddress, "123456");
143 #### Finally submit the transaction
146 Transaction.SubmitResponse txs = Transaction.submit(client, singer);
150 ### All usage examples
152 For more details you can see [doc](https://github.com/Bytom/bytom-java-sdk/blob/master/doc/index.md#api-methods). And you can find Test Cases at [Junit Test Cases](https://github.com/Bytom/bytom-java-sdk/tree/master/src/test/java/io/bytom/integration)
154 ## Support and Feedback
156 If you find a bug, please submit the issue in Github directly by using [Issues](https://github.com/Bytom/bytom-java-sdk/issues)
160 Bytom JAVA SDK is based on the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) protocol.