Git Product home page Git Product logo

java-bytom's Introduction

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

Latest Version Total Downloads

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.

http://www.opensource.org/licenses/MIT

java-bytom's People

Contributors

jackyken avatar niyuelin1990 avatar sugeladi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.