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
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.
<dependency>
<groupId>io.bytom</groupId>
<artifactId>bytom-sdk-java</artifactId>
<version>1.0.2</version>
</dependency>
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 git@github.com:chainworld/java-bytom.git
cd java-bytom
mvn install
This guide will walk you through the basic functions of Bytom:
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);
}
Key key = Key.create(client, "alias", "password");
It will create a key whose alias is 'alias' while password is 'password'.
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, providing an alias, key, and quorum.
Account account = new Account.Builder()
.setAlias("alice")
.addXpub(key.xpub)
.setQuorum(1)
.create(client);
new Account.ReceiverBuilder()
.setAccountId(account.id)
.create(client);
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);
Transaction.Template singerTx = new Transaction.SignerBuilder()
.sign(client,controlAddressTx, "password");
Transaction.submit(client, singerTx);
You find more detailed documentation at /doc. Also you can find Test Cases at Junit Test Cases
If you find a bug, please submit the issue in Github directly. Bytom-JAVA-SDK Issues
Bytom JAVA SDK is based on the MIT protocol.