Bytom JAVA SDK使用指南

匿名 (未验证) 提交于 2019-12-02 21:53:52
最近在开源社区协助比原链完成了 java sdk,这里跟大家分享下哈。

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

SDK 比较容易接入,以下是其中一个例子,更多的例子请查看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.
有多种方式可以安装Bytom JAVA SDK,例举如下,注意SDK需要Java 7版本及更高版本。

Maven

在Maven配置文件中添加如下配置:

<dependency>   <groupId>io.bytom</groupId>   <artifactId>bytom-sdk-java</artifactId>   <version>1.0.1</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):

从github上clone,编译并安装到你本地的Maven仓库中:

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:
这个指南会带你快速使用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.

创建一个SDK的实例,默认会连接你本地(http://127.0.0.1:9888)的core:

 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’.
创建一个别名为“alias”、密码为“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

License

Bytom JAVA SDK is based on the MIT protocol.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!