Bytom Java SDK
This SDK contains methods for easily interacting with the Bytom API. Below are examples to get you started. For more information, please see Bytom API reference documentation at https://github.com/Bytom/bytom/wiki
Table of Contents
Installation
There are various ways to install and use this sdk. We'll elaborate on a couple here. Note that the Bytom JAVA SDK requires JAVA 7 or newer.
Maven
<dependency>
<groupId>io.bytom</groupId>
<artifactId>bytom-sdk-java</artifactId>
<version>1.0.2</version>
</dependency>
Building from source code
To clone, compile, and install in your local maven repository (or copy the artifacts from the target/ directory to wherever you need them):
git clone [email protected]:chainworld/java-bytom.git
cd java-bytom
mvn install
5-Minute Guide
This guide will walk you through the basic functions of Bytom:
Initialize the SDK
Create an instance of the SDK. By default, the SDK will try to access a core located at http://127.0.0.1:9888, which is the default if you’re running Bytom Wallet locally.
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);
}
Create Keys
Key key = Key.create(client, "alias", "password");
It will create a key whose alias is 'alias' while password is 'password'.
Create an Asset
Create a new asset, providing an alias, key, and quorum.
String asset = "GOLD";
Asset testAsset = new Asset.Builder()
.setAlias(asset)
.addRootXpub(key.xpub)
.setQuorum(1)
.create(client);
Create an Account
Create an account, providing an alias, key, and quorum.
Account account = new Account.Builder()
.setAlias("alice")
.addXpub(key.xpub)
.setQuorum(1)
.create(client);
Create an Account Address
new Account.ReceiverBuilder()
.setAccountId(account.id)
.create(client);
Build the Transaction
Transaction.Template controlAddressTx = new Transaction.Builder()
.addAction(new Transaction.Action.SpendFromAccount()
.setAccountId(account.id)
.setAssetId(asset.id)
.setAmount(300000000))
.addAction(new Transaction.Action.ControlWithAddress()
.setAddress(address.id)
.setAssetId(asset.id)
.setAmount(200000000))
.build(client);
Sign the Transaction
Transaction.Template singerTx = new Transaction.SignerBuilder()
.sign(client,controlAddressTx, "password");
Submit the Transaction
Transaction.submit(client, singerTx);
All usage examples
You find more detailed documentation at /doc. Also you can find Test Cases at Junit Test Cases
Support and Feedback
If you find a bug, please submit the issue in Github directly. Bytom-JAVA-SDK Issues
License
Bytom JAVA SDK is based on the MIT protocol.