https://github.com/chainworld/java-bytom
Bytom Java SDK
https://github.com/chainworld/java-bytom
blockchain bytom java sdk
Last synced: 6 months ago
JSON representation
Bytom Java SDK
- Host: GitHub
- URL: https://github.com/chainworld/java-bytom
- Owner: chainworld
- Created: 2018-05-08T08:14:05.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T06:09:44.000Z (almost 8 years ago)
- Last Synced: 2025-07-09T09:22:12.693Z (about 1 year ago)
- Topics: blockchain, bytom, java, sdk
- Language: JavaScript
- Homepage: https://bytom.io/
- Size: 1.88 MB
- Stars: 6
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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
[](https://github.com/lxlxw/bytom-php-sdk/releases)
[](https://packagist.org/packages/lxlxw/bytom-php-sdk)
## Table of Contents
- [Installation](#installation)
- [Maven](#maven)
- [Building from source code](#building-from-source-code)
- [5-Minute Guide](#5-minute-guide)
- [Initialize the SDK](#initialize-the-sdk)
- [Create Keys](#create-keys)
- [Create an Asset](#create-an-asset)
- [Create an Account](#create-an-account)
- [Create an Account Address](#create-an-account-address)
- [Build the Transaction](#build-the-transaction)
- [Sign the Transaction](#sign-the-transaction)
- [Submit the Transaction](#submit-the-transaction)
- [All usage examples](#all-usage-examples)
- [Support and Feedback](#support-and-feedback)
- [License](#license)
## 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
```
io.bytom
bytom-sdk-java
1.0.2
```
### 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):
```bash
git clone git@github.com: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.
```java
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
```java
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.
```java
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.
```java
Account account = new Account.Builder()
.setAlias("alice")
.addXpub(key.xpub)
.setQuorum(1)
.create(client);
```
### Create an Account Address
```java
new Account.ReceiverBuilder()
.setAccountId(account.id)
.create(client);
```
### Build the Transaction
```java
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
```java
Transaction.Template singerTx = new Transaction.SignerBuilder()
.sign(client,controlAddressTx, "password");
```
### Submit the Transaction
```java
Transaction.submit(client, singerTx);
```
### All usage examples
You find more detailed documentation at [/doc](doc/index.md).
Also you can find Test Cases at [Junit Test Cases](/src/test/java/io/bytom/integration)
## Support and Feedback
If you find a bug, please submit the issue in Github directly.
[Bytom-JAVA-SDK Issues](https://github.com/chainworld/java-bytom/issues)
## License
Bytom JAVA SDK is based on the MIT protocol.