博客专区 > 光斑 的博客 > 博客详情
光斑 发表于5个月前
  • 发表于 5个月前
  • 阅读 9
  • 收藏 0
  • 点赞 0
  • 评论 0


Stellar Network Overview

Stellar Ecosystem

Create an Account

package com.step.controller;
import org.stellar.sdk.KeyPair;
import java.util.*;
import org.stellar.sdk.Server;
import org.stellar.sdk.responses.AccountResponse;

 * Created by weixiang.wu on 2017/9/8.
public class Test {
    public static void main(String[] args) throws IOException, DecoderException {
        KeyPair pair = KeyPair.random();
        System.out.println(new String(pair.getSecretSeed()));
        String friendbotUrl = String.format(
        InputStream response = new URL(friendbotUrl).openStream();
        String body = new Scanner(response, "UTF-8").useDelimiter("\\A").next();
        System.out.println("SUCCESS! You have a new account :)\n" + body);
        Server server = new Server("");
        AccountResponse account = server.accounts().account(KeyPair.fromAccountId(pair.getAccountId()));
        System.out.println("Balances for account " + pair.getAccountId());
        for (AccountResponse.Balance balance : account.getBalances()) {
                    "Type: %s, Code: %s, Balance: %s",

Send Payments

Actions that change things in Stellar, like sending payments, changing your account, or making offers to trade various kinds of currencies, are called operations.[1] In order to actually perform an operation, you create a transaction, which is just a group of operations accompanied by some extra information, like what account is making the transaction and a cryptographic signature to verify that the transaction is authentic.[2]

If any operation in the transaction fails, they all fail. For example, let’s say you have 100 lumens and you make two payment operations of 60 lumens each. If you make two transactions (each with one operation), the first will succeed and the second will fail because you don’t have enough lumens. You’ll be left with 40 lumens. However, if you group the two payments into a single transaction, they will both fail and you’ll be left with the full 100 lumens still in your account.

Finally, every transaction costs a small fee. Like the minimum balance on accounts, this fee helps stop people from overloading the system with lots of transactions. Known as the base fee, it is very small—100 stroops per operation (that’s 0.00001 XLM; stroops are easier to talk about than such tiny fractions of a lumen).

A transaction with two operations would cost 200 stroops.[3]

Building a Transaction

Stellar stores and communicates transaction data in a binary format called XDR.[4] Luckily, the Stellar SDKs provide tools that take care of all that. Here’s how you might send 10 lumens to another account:

     * 创建一笔交易
     * @param source1      来源账户
     * @param destination1 目标账户
     * @param hash         上传文件的hash值
     * @throws IOException
    public static void buildingTransaction(String source1, String destination1, String hash) throws IOException, DecoderException {
        Logger logger = org.apache.log4j.LogManager.getLogger(BuildingTransaction.class);
          /*新网络 Network提供获取不同恒星网络的密码或id,提供了
        Network.current 类方法,返回该进程将用于生成签名的网络
        usePublicNetwork(恒星公共网络) 或者 useTestNetWork(测试网络) 方法。
        Server server = new Server("");
        KeyPair source = null;
        try {
            source = KeyPair.fromSecretSeed(source1);
        } catch (Exception e) {
            throw new RuntimeException("私钥验证失败!");

        KeyPair destination = null;
        try {
            destination = KeyPair.fromAccountId(destination1);
        } catch (Exception e) {
            throw new RuntimeException("公钥验证失败!");

        // 交易的序列号需要与帐户的序列号匹配,oi。
        AccountResponse sourceAccount = server.accounts().account(source);

        //new PaymentOperation.Builder(destination(将资产发送到目的帐户), new AssetTypeNative()(返回资产的类型), "0.00001"(asset发送的资产总额))创建一个新的PaymentOperation构建器
        Transaction transaction = new Transaction.Builder(sourceAccount)
                .addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "0.00001"/*浮点数可能会不准确*/).build())
        try {
            SubmitTransactionResponse response = server.submitTransaction(transaction);
        } catch (Exception e) {
            logger.error("创建交易时发生异常,异常信息:", e);


  • 点赞
  • 收藏
  • 分享
粉丝 5
博文 146
码字总数 140410